Pointers and Arrays - Dox
Pointers and Arrays - Dox
1. 2. 3. 4. 5. 6. 7. 8. 9. } #include <stdio.h> int main() { const int ary[4] = {1, 2, 3, 4}; int *p; p = ary + 3; *p = 5; printf("%d\n", ary[3]);
a) 5 5 5 b) 5 5 junk value
a) Different address is printed b) 1 2 c) Same address is printed. d) 1 1 6. What is the output of this C code?
1. 2. 3. 4. #include <stdio.h> int main() { int a = 1, b = 2, c = 3;
5. 6. 7. 8. }
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c; int **sptr = &ptr1; //-Ref *sptr = ptr2;
a) ptr1 points to a b) ptr1 points to b c) sptr points to ptr2 d) None of the mentioned 7. What is the output of this C code?
1. 2. 3. 4. 5. 6. } #include <stdio.h> void main() { char a[10][5] = {"hi", "hello", "fellows"}; printf("%s", a[2]);
2. 3. 4. 5. 6.
a) 2 b) 4 c) 5 d) 10 10) Which of the following statements are true? P. Pointer to Array Q. Multi-dimensional array a) P are static, Q are static b) P are static, Q are dynamic c) P are dynamic, Q are static d) P are dynamic, Q are dynamic 11 What is the output of this C code?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. } }; struct student s; no = 8; printf("%d", no); #include <stdio.h> void main() { struct student { int no; char name[20];
a) Nothing b) Compile time error c) Junk d) 8 12 What is the output of this C code?
1. #include <stdio.h>
struct student { int no; char name[20]; }; void main() { struct student s; s.no = 8; printf("hello"); }
a) Run time error b) Nothing c) hello d) Varies 13 What is the output of this C code?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. } }; void main() { struct student s; s.no = 8; printf("hello"); #include <stdio.h> struct student { int no = 5; char name[20];
a) Nothing b) Compile time error c) hello d) Varies 14 What is the output of this C code?
1. 2. 3. #include <stdio.h> struct student {
int no; char name[20]; void main() { student s; s.name = "hello"; printf("hello");
a) Nothing b) hello c) Compile time error d) Varies 15. What is the output of this C code?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. } }; struct student s; s.no = 8; printf("%s", s.name); #include <stdio.h> void main() { struct student { int no; char name[20];
a) Nothing b) Compile time error c) Junk d) 8 16 Comment on the output of this C code?
1. 2. 3. 4. 5. #include <stdio.h> int main() { char *str = "This" //Line 1 char *ptr = "Program\n"; //Line 2
6. 7. 8. }
a) Memory holding this is cleared at line 3 b) Memory holding this loses its reference at line 3 c) You cannot assign pointer like in Line 3 d) Output will be This, Program 17. What type initialization is needed for the segment ptr[3] = 3; to work? a) char *ptr = Hello!; b) char ptr[] = Hello!; c) Both (a) and (b) d) None of the mentioned 18. The syntax for constant pointer to address (i.e., fixed pointer address) is:
a) b) c) d) const <type> * <name> <type> * const <name> <type> const * <name> Both (a) and (c)
a) Compile time error, declaration of a function inside main. b) Compile time error, no definition of function fn_ptr. c) Compile time error, illegal application of statement fn_ptr = add. d) No Run time error, output is 5
20. Calling a function f with a an array variable a[3] where a is an array, is equivalent to a) f(a[3]) b) f(*(a + 3)) c) f(3[a]) d) All of the mentioned 21. What is the output of this C code?
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. } } void main() { char s[] = "hello"; f(s); printf("%c\n", *s); #include <stdio.h> void f(char *k) { k++; k[2] = 'm';
a) h b) e c) m d) o;