#Include : Void Int Int Int

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

the output of this C code?

1.

#include <stdio.h>

2.

void foo(int*);

3.

int main()

4.

5.

int i = 10;

6.

foo((&i)++);

7.

8.

void foo(int *p)

9.

10.
11.

printf("%d\n", *p);
}

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash
View Answer
Answer:c
2. What is the output of this C code?
1.

#include <stdio.h>

2.

void foo(int*);

3.

int main()

4.

5.

int i = 10, *p = &i;

6.

foo(p++);

7.

8.

void foo(int *p)

9.

10.
11.

printf("%d\n", *p);
}

a) 10
b) Some garbage value
c) Compile time error

d) Segmentation fault
View Answer
Answer:a
3. What is the output of this C code?
1.

#include <stdio.h>

2.

void foo(float *);

3.

int main()

4.

5.

int i = 10, *p = &i;

6.

foo(&i);

7.

8.

void foo(float *p)

9.

10.
11.

printf("%f\n", *p);
}

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
View Answer
Answer:b
4. What is the output of this C code?
1.

#include <stdio.h>

2.

int main()

3.

4.

int i = 97, *p = &i;

5.

foo(&i);

6.

printf("%d ", *p);

7.

8.

void foo(int *p)

9.

10.

int j = 2;

11.

p = &j;

12.
13.

printf("%d ", *p);


}

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash
View Answer
Answer:a
5. What is the output of this C code?
1.

#include <stdio.h>

2.

int main()

3.

4.

int i = 97, *p = &i;

5.

foo(&p);

6.

printf("%d ", *p);

7.

return 0;

8.

9.

void foo(int **p)

10.

11.

int j = 2;

12.

*p = &j;

13.

printf("%d ", **p);

14.

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash
View Answer
Answer:a
6. What is the output of this C code?
1.

#include <stdio.h>

2.

int main()

3.

4.

int i = 11;

5.

int *p = &i;

6.

foo(&p);

7.

printf("%d ", *p);

8.

9.

void foo(int *const *p)

10.

11.

int j = 10;

12.

*p = &j;

13.

printf("%d ", **p);

14.

a) Compile time error


b) 10 10
c) Undefined behaviour
d) 10 11
View Answer

You might also like