wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CODE CAREER

Total questions: 9

Worksheet time: 9mins

Name
Class
Date
1.

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; 

a)

5 20

b)

50 0

c)

5 5

d)

Compile Error

2.

2. What is the output of the following code? 

int main (){ 

char *ptr = "Innoskrit"; 

printf("%c", &&*ptr); 

return 0; 

a)

I

b)

Innoskrit

c)

Segmentation Fault 

d)

Compile Error 

3.

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; 

a)

0 2

b)

2 2

c)

1 2

d)

0 1

4.

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

a)

18

b)

19

c)

21

d)

22

5.

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; 

a)

12

b)

Compile Error

c)

Runtime Error

d)

0

6.

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; 

a)

2

b)

3

c)

4

d)

Compile Error

7.

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

a)

10

b)

20

c)

30

d)

40

8.

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; 

a)

300

b)

556

c)

Compile Error

d)

Runtime Error

9.

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

a)

1, 0

b)

0, 0

c)

2, 0

d)

1, 0