NEW
Font size
WorksheetsCODE CAREER
Total questions: 9
Worksheet time: 9mins
1. What is the output of the following code?
#include<stdio.h>
int main()
{
int arr[] = {10,20,30,40,50,60};
int *ptr1 = arr;
int *ptr2 = arr + 5;
printf("%d ", (ptr2 - ptr1));
printf("%d", (char*)ptr2 - (char*)ptr1);
return 0;
}
5 20
50 0
5 5
Compile Error
2. What is the output of the following code?
int main (){
char *ptr = "Innoskrit";
printf("%c", &&*ptr);
return 0;
}
I
Innoskrit
Segmentation Fault
Compile Error
3. What is the output of the following code?
void f(int p, int q){
p = q;
*p = 2;
}
int i = 0, j = 1;
int main(){
f(&i, &i);
printf("%d %d \n", i,j);
getchar();
return 0;
}
0 2
2 2
1 2
0 1
4. What is the output of the following code?
#include <stdio.h>
int f(int x, int py, int*ppz){
int y, z;
**ppz += 1;
z = **ppz;
*py +=2;
y = *py;
x +=3;
return x+y+z;
}
void main(){
int c, b, *a;
c = 4;
b = &c;
a = &b;
printf("%d", f(c,b,a));
}
18
19
21
22
5. What is the output of the following code?
#include <stdio.h>
int main(){
int a = 12;
void ptr =(int)&a;
printf("%d", *ptr);
getchar();
return 0;
}
12
Compile Error
Runtime Error
0
6. What is the output of the following code?
#include <stdio.h>
int main(){
int arr[] = {1,2,3,4,5};
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
return 0;
}
2
3
4
Compile Error
7. What is the output of the following code?
#include <stdio.h>
void f(int* p, int m){
m = m + 5;
p = p + m;
return;
}
void main (){
int i = 5, j = 10;
f(&i,j);
printf("%d", i+j);
}
10
20
30
40
8. What is the output of the following code? Consider the size of int as two bytes and size of char as one byte. Assume that the machine is little-endian.
#include <stdio.h>
int main() {
int a = 300;
char b = (char ) &a;
*++b = 2;
printf("%d", a);
return 0;
}
300
556
Compile Error
Runtime Error
9. Consider the following function implemented in C. The output of printxy(1,1) is ?
void printxy(int x, int y) {
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d",x,y);
}
1, 0
0, 0
2, 0
1, 0
