Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views12 pages

C Arrays

Uploaded by

dhakshanms06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views12 pages

C Arrays

Uploaded by

dhakshanms06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1. What is the output of the following code?

#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = (int*)(&a + 1);
printf("%d %d", *(a + 1), *(p - 1));
return 0;
}
Options:
A) 2 5
B) 2 4
C) 1 5
D) Segmentation Fault

2. What does the following code print?


#include <stdio.h>
int main() {
int arr[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
printf("%d", *(*(arr + 1) + 2) + *(arr[2] + 1));
}
Options:
A) 12
B) 14
C) 15
D) Compilation Error

3. What is the output?


#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int *ptr1 = arr;
int *ptr2 = arr + 4;
printf("%ld", (ptr2 - ptr1) * sizeof(*ptr1));
}
Options:
A) 16
B) 4
C) 20
D) Undefined Behavior

4. What does this code output?


#include <stdio.h>
int main() {
int a[3] = {0};
int *b = a;
printf("%d", b[2] + 2[b]);
}
Options:
A) 0
B) 4
C) Compilation Error
D) Undefined Behavior

5. What is the output?


#include <stdio.h>
int main() {
int arr[][3] = {1, 2, 3, 4, 5, 6};
printf("%d", *(*(arr + 1) + 1) + arr[0][2]);
}
Options:
A) 8
B) 9
C) 10
D) Compilation Error
6. What does this code print?
#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = &a[3];
int *q = &a[0];
printf("%d", p[-1] + q[2]);
}
Options:
A) 5
B) 6
C) 7
D) Undefined Behavior

7. What is the output?


#include <stdio.h>
int main() {
int arr[2][2] = {{1, 2}, {3, 4}};
int (*p)[2] = arr;
printf("%d", p[1][0] + (*p)[1]);
}
Options:
A) 4
B) 5
C) 6
D) Compilation Error

8. What does this code output?


#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4};
int *p = a + 3;
printf("%d", p[-2] + a[p - a]);
}
Options:
A) 4
B) 5
C) 6
D) Undefined Behavior

9. What is the output?


#include <stdio.h>
int main() {
int arr[3] = {10, 20, 30};
int *p = arr;
printf("%d", ++*p + *(p++));
}
Options:
A) 21
B) 22
C) Undefined Behavior
D) Compilation Error

10. What does this code print?


#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = (int*)((char*)a + sizeof(int) * 2);
printf("%d", *p);
}
Options:
A) 1
B) 2
C) 3
D) Undefined Behavior
11. What is the output?
#include <stdio.h>
int main() {
int arr[][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
printf("%d", *(*arr + 6) + arr[1][-2]);
}
Options:
A) 8
B) 10
C) 12
D) Undefined Behavior

12. What does this code print?


#include <stdio.h>
int main() {
int a[] = {0, 1, 2, 3, 4};
int *p = &a[2], *q = &a[4];
printf("%d", q - p + *p);
}
Options:
A) 4
B) 5
C) 6
D) Undefined Behavior

13. What is the output?


#include <stdio.h>
int main() {
int arr[3] = {10, 20, 30};
printf("%d", 0[arr] + (1[arr + 1]));
}
Options:
A) 30
B) 40
C) 50
D) Compilation Error

14. What does this code output?


#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = a + 3;
printf("%d", p[*(p - 2)] + a[p - a]);
}
Options:
A) 6
B) 7
C) 8
D) Undefined Behavior

15. What is the output?


#include <stdio.h>
int main() {
int arr[2][3] = {1, 2, 3, 4, 5, 6};
printf("%d", *(*(arr + 1) - 1) + arr[0][2]);
}
Options:
A) 5
B) 6
C) 7
D) Undefined Behavior

16. What does this code print?


#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4};
int *p = a + 1;
printf("%d", (*p)++ + *p);
}
Options:
A) 4
B) 5
C) Undefined Behavior
D) Compilation Error

17. What is the output?


#include <stdio.h>
int main() {
int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}};
printf("%d", *(arr[1] + 1) + *(*(arr + 2) - 1));
}
Options:
A) 7
B) 8
C) 9
D) Undefined Behavior

18. What does this code output?


#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = (int*)((char*)a + sizeof(int) * 2 + 1);
printf("%d", *p);
}
Options:
A) 3
B) Garbage Value
C) Segmentation Fault
D) Compilation Error

19. What is the output?


#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40};
int *p = arr;
printf("%d", *p++ + ++*p);
}
Options:
A) 31
B) 41
C) Undefined Behavior
D) Compilation Error

20. What does this code print?


#include <stdio.h>
int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", a[1][2] + 2[1[a]]);
}
Options:
A) 12
B) 14
C) 16
D) Undefined Behavior

21. What is the output of the following code?


#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *p = arr + 2;
printf("%d", p[*(p - 1)] - *(p + 1));
}
Options:
A) 0
B) 1
C) 2
D) Undefined Behavior

22. What does this code print?


#include <stdio.h>
int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printf("%d", *(*(a + 1) + 1) + a[1][1]);
}
Options:
A) 5
B) 10
C) 11
D) Undefined Behavior

23. What is the output?


#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int *p = (int *)((char *)arr + sizeof(int) * 2 + 1);
printf("%d", *p);
}
Options:
A) 30
B) Garbage Value
C) Segmentation Fault
D) Compilation Error

24. What does this code output?


#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4};
int *p = a + 1;
printf("%d", (*p)++ + (*p)++);
}
Options:
A) 4
B) 5
C) Undefined Behavior
D) Compilation Error

25. What is the output?


#include <stdio.h>
int main() {
int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
printf("%d", *(*(arr) + 5) + arr[1][-1]);
}
Options:
A) 7
B) 8
C) 9
D) Undefined Behavior

26. What does this code print?


#include <stdio.h>
int main() {
int a[5] = {1, 2, 3, 4, 5};
int *p = &a[3], *q = &a[0];
printf("%d", p[-1] + q[3] + a[*q]);
}
Options:
A) 9
B) 10
C) 11
D) Undefined Behavior

27. What is the output?


#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *p = arr + 1;
printf("%d", *(p + (*p - 1)) + (*p)++);
}
Options:
A) 5
B) 6
C) Undefined Behavior
D) Compilation Error

28. What does this code output?


#include <stdio.h>
int main() {
int a[][2] = {1, 2, 3, 4, 5, 6};
printf("%d", *(*(a + 2) - 1) + a[1][1]);
}
Options:
A) 7
B) 8
C) 9
D) Undefined Behavior
29. What is the output?
#include <stdio.h>
int main() {
int arr[3] = {10, 20, 30};
printf("%d", *arr + *(arr + *arr - *arr));
}
Options:
A) 20
B) 30
C) Undefined Behavior
D) Compilation Error

30. What does this code print?


#include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4};
int *p = a + 2;
printf("%d", (*p)-- + (*p)--);
}
Options:
A) 6
B) 5
C) Undefined Behavior
D) Compilation Error

You might also like