Question 1 of 25
Hints left: 3
Q1
Comment on the output of the following C code. #include <stdio.h> int main() { char *str = "This" //Line 1 char *ptr = "Program\n"; //Line 2 str = ptr; //Line 3 printf("%s, %s\n", str, ptr); //Line 4 }
Q2
What are the different ways to initialize an array with all elements as zero?
Q3
What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
Q4
What will be the output of the following C code? #include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; **m = 6; printf("%d\n", k); }
Q5
What will be the output of the following C code? #include <stdio.h> void f(int a[][]) { a[0][1] = 3; int i = 0, j = 0; for (i = 0;i < 2; i++) for (j = 0;j < 3; j++) printf("%d", a[i][j]); } void main() { int a[2][3] = {0}; f(a); }
Q6
Which of the following declaration is illegal?
Q7
Which of the following are generated from char pointer?
Q8
What will be the output of the following C code? #include <stdio.h> 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)); }
Q9
Which of following logical operation can be applied to pointers? (Assuming initialization int *a = 2; int *b = 3;)
Q10
What will be the output of the following C code? #include <stdio.h> 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; }
Q11
What will be the output of the following C code? #include <stdio.h> int main() { int *((*x)())[2]; x(); printf("after x\n"); } int *((*x)())[2] { int **str; str = (int*)malloc(sizeof(int)* 2); return str; }
Q12
What will be the output of the following C code? #include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d\n", k, *p, **m); }
Q13
What will be the output of the following C code? #include <stdio.h> void main() { char *s = "hello"; char *n = "cjn"; char *p = s + n; printf("%c\t%c", *p, s[1]); }
Q14
What will be the output of the following C code? #include <stdio.h> 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)); }
Q15
What will be the output of the following C code? #include <stdio.h> int main() { int a[4] = {1, 2, 3, 4}; int *ptr = &a[2]; float n = 1; ptr = ptr + n; printf("%d\n", *ptr); }
Q16
What will be the output of the following C code? #include <stdio.h> struct student { int no; char name[20]; }; void main() { student s; s.name = "hello"; printf("hello"); }
Q17
What will be the output of the following C code? #include <stdio.h> void f(int); void (*foo)(float) = f; int main() { foo(10); } void f(int i) { printf("%d\n", i); }
Q18
Which of the following is the correct syntax to declare a 3 dimensional array using pointers?
Q19
What will be the output of the following C code? #include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }
Q20
What will be the output of the following C code? #include <stdio.h> int main() { int i = 10; void *p = &i; printf("%f\n", *(float*)p); return 0; }
Q21
What will be the output of the following C code? #include <stdio.h> int main() { int ary[4] = {1, 2, 3, 4}; int p[4]; p = ary; printf("%d\n", p[1]); }
Q22
What is the maximum number of arguments that can be passed in a single function?
Q23
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
Q24
What will be the output of the following C code? #include <stdio.h> int *f(); int main() { int *p = f(); printf("%d\n", *p); } int *f() { int j = 10; return &j; }
Q25
What will be the output of the following C code? #include <stdio.h> void f(char *k) { k++; k[2] = 'm'; printf("%c\n", *k); } void main() { char s[] = "hello"; f(s); }