Pointers Questions
Practice Pointers MCQs with answers and explanations. Page 1 of 2.
Category
C Programming
Topic
Pointers
Page
1 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Pointers and dereferencing in C: which operator retrieves the value stored at the memory address contained in a pointer variable?
Open
View answer
C standard macros: in which standard header(s) is the macro NULL guaranteed to be defined?
Open
View answer
In C pointer terminology, what does the expression (void*)0 represent?
Open
View answer
Accessing structure members through a pointer in C: which operator should be used to reach a field of a struct via a pointer variable?
Open
View answer
In C/C++, can the two statements 'char p;' and 'p = (char) malloc(100);' be combined into a single declaration-and-initialization statement? Select the correctly formed combined statement.
Open
View answer
In C programming, what is a pointer most accurately described as (choose the best definition in the context of variables and memory addresses)?
Open
View answer
In 16-bit DOS memory models, how many bytes are used by near, far, and huge pointers respectively?
Open
View answer
For a four-dimensional array a[i][j][k][l] in C, which equivalent pointer expression correctly refers to that element using pointer arithmetic and dereferencing?
Open
View answer
C format strings, pointer arithmetic, and printf: what does this program print?
#include<stdio.h>
int main()
{
char *str;
str = "%d
";
str++;
str++;
printf(str-2, 300);
return 0;
}
Open
View answer
C printf with a string format specifier: what is printed?
#include<stdio.h>
int main()
{
char str;
str = "%s";
printf(str, "K
");
return 0;
}
Open
View answer
Pointer-based string copy with printing at each step (assume enough destination space): what final string does str1 hold after the loop?
#include<stdio.h>
int main()
{
char str1[20] = "India"; // assume sufficient space to avoid overflow
char str2[] = "CURIOUSTAB";
char *s1 = str1, *s2 = str2;
while (*s1++ = *s2++)
printf("%s", str1);
printf("
");
return 0;
}
(We focus on the final content stored in str1 after copying completes.)
Open
View answer
Pointer arithmetic and 2D arrays in C (row-major layout): assuming the base address of a begins at 1002 and sizeof(int) = 4 bytes, what does the following print?
#include<stdio.h>
int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf("%u, %u, %u
", a[0]+1, (a[0]+1), ((a+0)+1));
return 0;
}
Open
View answer
In C (pointer decay with multidimensional arrays), what will this print if the array 'a' begins at address 1002?
#include<stdio.h>
int main()
{
int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},
{2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
printf("%u, %u, %u, %d
", a, *a, **a, ***a);
return 0;
}
Open
View answer
In C strings and pointers, what does this print (note: writing to a string literal is undefined; assume it succeeds for this exercise)?
#include<stdio.h>
#include<string.h>
int main()
{
int i, n;
char *x = "Alice";
n = strlen(x);
*x = x[n];
for (i = 0; i <= n; i++)
{
printf("%s ", x);
x++;
}
printf("
");
return 0;
}
Open
View answer
In C (pointers to pointers), given 4-byte int, what does this print?
#include<stdio.h>
int main()
{
int ***r, **q, *p, i = 8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d
", *p, **q, ***r);
return 0;
}
Open
View answer
In C pointer arithmetic with post-increment on pointers, assume &x = 500 and sizeof(int) = 4 bytes. What prints?
#include<stdio.h>
int main()
{
int x = 30, *y, z;
y = &x; / &x is 500 */
z = y;
*y++ = *z++;
x++;
printf("x=%d, y=%d, z=%d
", x, y, z);
return 0;
}
Open
View answer
In C, casting addresses through void* inside a function: what is printed?
#include<stdio.h>
void fun(void *p);
int i;
int main()
{
void vptr;
vptr = &i; / global i zero-initialized /
fun(vptr);
return 0;
}
void fun(void p)
{
int q;
q = (int)&p;
printf("%d
", q);
}
Open
View answer
In C, mixing char* and int* and unaligned reads: what prints?
#include<stdio.h>
int main()
{
int arr[3] = {2, 3, 4};
char p;
p = (char)arr;
p = (char*)((int*)(p));
printf("%d, ", p);
p = (int)(p + 1);
printf("%d", p);
return 0;
}
Open
View answer
In C, using sizeof with arrays and elements (int is 4 bytes): what is printed?
#include<stdio.h>
int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d
", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
Open
View answer
In C, address-of and dereference cancellation with a char pointer: what is printed?
#include<stdio.h>
int main()
{
char p;
p = "hello";
printf("%s
", &&p);
return 0;
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.