Home > C Programming > Quizzes > C Programming Practice Test: Pointers and Arrays in C
C Programming Practice Test: Pointers and Arrays in C
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What is the syntax for constant pointer to address (i.e., fixed pointer address)…”
Pointers and Arrays in C quiz on: Pointers and addresses, function arguments, arrays, address arithmetic, character pointers and functions, multidimensional arrays, pointer arrays initialization, command line arguments and complicated declarations. Arrays: Arrays are used to store multiple elements of the same data type in a contiguous block of memory. The index of an array represents the position of an element, starting from 0. Arrays are static, which means that their size is fixed once they are declared. Pointers: Pointers are variables that store the address of another variable or array... Show more
C Programming Practice Test: Pointers and Arrays in C
Time left 00:00
25 Questions

1. Calling a function f with a an array variable a[3] where a is an array, is equivalent to __________
2. Which of the following operation is possible using a pointer char? (Assuming the declaration is char *a;)
3. What will be the output of the following C code?
#include
void f(int (*x)(int));
int myfoo(int);
int (*foo)() = myfoo;
int main()
{
f(foo);
}
void f(int(*i)(int ))
{
i(11);
}
int myfoo(int i)
{
printf("%d\n", i);
return i;
}
4. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
5. What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
6. What will be the output of the following C code?
#include
void main()
{
int a[2][3] = {1, 2, 3, , 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}
7. What will be the output of the following C code?
#include
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
8. What will be the output of the following C code?
#include
void f(int);
void (*foo)() = f;
int main(int argc, char *argv[])
{
foo(10);
return 0;
}
void f(int i)
{
printf("%d\n", i);
}
9. Arguments that take input by user before running a program are called?
10. What will be the output of the following C code?
#include
int main()
{
char a[1][5] = {"hello"};
printf("%s", a[0]);
return 0;
}
11. What will be the output of the following C code?
#include
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%s", s.name);
}
12. What will be the output of the following C code on a 32-bit system?
#include
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a));
}
13. What is the syntax for constant pointer to address (i.e., fixed pointer address)?
14. Which of the following is the correct syntax to declare a 3 dimensional array using pointers?
15. Comment on the following 2 arrays with respect to P and Q.
int *a1[8];
int *(a2[8]);
P. Array of pointers
Q. Pointer to an array
16. What will be the output of the following C code?
#include
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%d", s.no);
}
17. What does argc and argv indicate in command-line arguments?
(Assuming: int main(int argc, char *argv[]) )
18. What will be the output of the following C code?
#include
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf("%d %d\n", p[-2], ary[*p]);
}
19. How many number of pointer (*) does C have against a pointer variable declaration?
20. What will be the output of the following C code?
#include
void (*(f)())(int, float);
void (*(*x)())(int, float) = f;
void ((*y)(int, float));
void foo(int i, float f);
int main()
{
y = x();
y(1, 2);
}
void (*(f)())(int, float)
{
return foo;
}
void foo(int i, float f)
{
printf("%d %f\n", i, f);
}
21. Read the following expression?
void (*ptr)(int);"
22. What will be the output of the following C code?
#include
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", *(a[i]));
}
23. What will be the output of the following C code?
#include
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int (*function_pointer)(int, int, int);
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}
24. What will be the output of the following C code?
#include
int main()
{
int i = 0, j = 1;
int *a[] = {&i, &j};
printf("%d", *a[0]);
return 0;
}
25. What type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?