TRE4 C and C++ Quiz practice set 1
Que: (1). Write the output of the following program: int a[ ] = {1,2,3,} *p;
int a[] = {1,2,3,} *p;
Que: (2). What will be the output of the following C program?
int a[] = {10,20,30,40};
int *p = a;
printf("%d", *(p + 2));
Que: (3). Which of the following is equivalent to a[3] in C?
Que: (4). What will be the output of the following C program?
int a[] = {5,10,15,20,25};
printf("%d", sizeof(a) / sizeof(a[0]));
Que: (5). What will be the output of the following C program?
int a[] = {11,22,33,44};
int *p = &a[1];
printf("%d", *p);
Que: (6). What will be the output of the following C program?
int a[] = {10,20,30};
int *p = a;
p++;
printf("%d", *p);
Que: (7). What will be the output of the following C program?
int a[5] = {1,2};
printf("%d", a[3]);
Que: (8). What will be the output of the following C program?
int a[] = {2,4,6,8};
int *p = &a[1];
printf("%d", p[2]);
Que: (9). What will be the output of the following C program?
int a[2][3] = {{1,2,3},{4,5,6}};
printf("%d", *(*(a+1)+2));
Que: (10). What will be the output of the following C program?
void swap(int *x, int *y) {
int temp = *x;
*x = *y;
*y = temp;
}
int main() {
int a = 10, b = 20;
swap(&a, &b);
printf("%d %d", a, b);
return 0;
}
Que: (11). Which of the following statements about arrays and pointers in C is correct?
Que: (12). Assume size of an integer as 4 bytes. What is the output of the above program?
#include <stdio.h>
int main()
{
int i = 5, j = 10, k = 15;
```
printf("%d ", sizeof(k /= i + j));
printf("%d", k);
return 0;
```
}
Que: (13). Assume that an integer occupies 4 bytes. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x = 10;
printf("%d", sizeof(x));
return 0;
}
Que: (14). Assume that an integer occupies 4 bytes. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int a[5] = {1, 2, 3, 4, 5};
```
printf("%d", sizeof(a));
return 0;
```
}
Que: (15). What will be the output of the following C program?
#include <stdio.h>
int main()
{
char c = 'A';
printf("%d", sizeof(c));
return 0;
}
Que: (16). What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x = 10;
```
printf("%d ", sizeof(x++));
printf("%d", x);
return 0;
```
}
Que: (17). What will be the output of the following C program?
#include <stdio.h>
int main()
{
int x = 10;
int *p = &x;
```
printf("%d %d", sizeof(x), sizeof(p));
return 0;
```
}
Que: (18). Which of the following statements about the sizeof operator in C is correct?
Que: (19). What will be the output of the following C program?
#include <stdio.h>
int main()
{
int a = 10, b = 20;
```
printf("%d", sizeof(a + b));
return 0;
```
}
Que: (20). What will be the output of the following C program?
#include <stdio.h>
int main()
{
int i = 5;
```
printf("%d ", sizeof(i++));
printf("%d", i);
return 0;
```
}
Que: (21). Assume that an integer occupies 4 bytes. What will be the output of the following C program?
#include <stdio.h>
int main()
{
int a[10];
```
printf("%d", sizeof(a) / sizeof(a[0]));
return 0;
```
}