0% found this document useful (0 votes)
272 views8 pages

Pointers and Arrays - Dox

The code defines a constant array ary with values {1, 2, 3, 4}. It sets p to point to the element at index 3 of ary, and assigns the value 5 to that element. It then prints the value at index 3 of ary. The output would be 5, as it assigns and prints the same element of ary.

Uploaded by

Ketan Fakeer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
272 views8 pages

Pointers and Arrays - Dox

The code defines a constant array ary with values {1, 2, 3, 4}. It sets p to point to the element at index 3 of ary, and assigns the value 5 to that element. It then prints the value at index 3 of ary. The output would be 5, as it assigns and prints the same element of ary.

Uploaded by

Ketan Fakeer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

1. What is the output of this C code?

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) 4 b) 5 c) Compile time error d) 3

2. Which of the following declaration is illegal?


a) int a = 0, b = 1, c = 2; int array[3] = {a, b, c}; b) int size = 3; int array[size]; c) int size = 3; int array[size] = {1, 2, 3}; d) All of the mentioned

3. What is the output of this C code?


1. 2. 3. 4. 5. 6. 7. 8. } #include <stdio.h> void main() { int k = 5; int *p = &k; int **m = &p; printf("%d%d%d\n", k, *p, **p);

a) 5 5 5 b) 5 5 junk value

c) 5 junk junk d) Compile time error

4. What is the output of this C code?


1. 2. 3. 4. 5. 6. 7. 8. 9. } #include <stdio.h> void main() { int k = 5; int *p = &k; int **m **m = 6; printf("%d\n", k); = &p;

a) 5 b) Compile time error c) 6 d) Junk 5. What is the output of this C code?


1. 2. 3. 4. 5. 6. 7. 8. } #include <stdio.h> void main() { int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a);

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]);

a) fellows b) fellow c) fello d) fell 8. What is the output of this C code?


1. 2. 3. 4. 5. 6. 7. } #include <stdio.h> void main() { char a[10][5] = {"hi", "hello", "fellows"}; printf("%p\n", a); printf("%p", a[0]);

a) Same address is printed b) Different address is printed c) hello d) hi hello fello 9


1.

What is the output of this C code?


#include <stdio.h>

2. 3. 4. 5. 6.

void main() { char a[10][5] = {"hi", "hello", "fellows"}; printf("%d", sizeof(a[1])); }

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>

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

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 {

4. 5. 6. 7. 8. 9. 10. 11. 12. } };

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. }

str = ptr; //Line 3 printf("%s, %s\n", str, ptr); //Line 4

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)

19. Comment on the output of this C code?


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. } } int main() { int (*fn_ptr)(int, int); fn_ptr = add; printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3)); #include <stdio.h> int add(int a, int b) { return a + b;

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;

22.What is the output of this C code?


1. 2. 3. 4. 5. 6. 7. } #include <stdio.h> void main() { char s[] = "hello"; s++; printf("%c\n", *s);

a) Compile time error b) h c) e d) o

You might also like