WorksheetsC Programming Quiz
Total questions: 10
Worksheet time: 5mins
In the following code, what is the output?
int a[] = {1, 2, 3};
int *b[3];
for(int k=0; k<3; k++)
b[k] = a + k;
printf("%d %d %d", *b[0], *b[1], *b[2]);
A) 1 1 1
B) 1 2 3
C) Address values
D) Compilation error
Which statement is true about this declaration? int **c[3];
A) c is a double pointer
B) c is a pointer to array of int
C) c is an array of pointers to pointer to int
D) c is a 2-D array
What is the output of the following code?
int a = 2, *p, **q;
p = &a;
q = &p;
printf("%d %d %d", a, *p, *q);
A) 2 2 2
B) 2 2 address
C) 2 address address
D) Compilation error
What will be printed?
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);
}
A) 20
B) 30
C) Garbage value
D) Runtime error
Identify the error in the following code:
int t[] = {1,2,3,4,5};
int *p, *q;
p = t;
q = p[1];
A) p = t is invalid
B) q = p[1] assigns int to pointer
C) Missing memory allocation
D) No error
What is the issue in the code below?
char *c;
float x = 10;
c = &x;
A) Syntax error
B) Assigning float to char
C) Incompatible pointer types
D) No error
What will be the output?
int x;
int *ptr = &x;
*ptr = 5;
*ptr += 1;
(*ptr)++;
printf("%d", x);
A) 0
B) 5
C) 6
D) 7
Assume: int = 4 bytes, char = 1 byte, pointer = 4 bytes.
What is the output?
int arri[] = {1,2,3};
int *ptri = arri;
printf("%d %d", sizeof(arri), sizeof(ptri));
A) 3 3
B) 12 12
C) 12 4
D) 4 12
Which is the correct way to access a structure member using a pointer? (assume that the variable name is 'a' and the value to assign is 5)
A) *ptr.a = 5;
B) ptr.a = 5;
C) (*ptr).a = 5;
D) ptr->a=5;
E) both C and D
Assume float takes 4 bytes. What is the output?
float arr[5] = {2.5, 1.0, 1.5, 9.5, 1.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 2;
printf("%f, %d", *ptr2, ptr2 - ptr1);
A) 1.5, 2.5
B) 1.5, 2
C) 2.5, 2
D) 12.5, address of arr[0]
