0% found this document useful (0 votes)
16K views4 pages

#Include : Void Int Int Int

The C code defines a function foo that takes in an integer pointer as a parameter. It then defines an integer i, assigns the address of i to a pointer p, and calls foo, passing the address of p. Within foo, it assigns the address of a new integer j to the pointer being passed in, effectively changing what p points to. The code then prints the values of j and what p now points to. The output is 2 2, as p is changed within foo to point to j instead of i.

Uploaded by

Suneela Mathe
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)
16K views4 pages

#Include : Void Int Int Int

The C code defines a function foo that takes in an integer pointer as a parameter. It then defines an integer i, assigns the address of i to a pointer p, and calls foo, passing the address of p. Within foo, it assigns the address of a new integer j to the pointer being passed in, effectively changing what p points to. The code then prints the values of j and what p now points to. The output is 2 2, as p is changed within foo to point to j instead of i.

Uploaded by

Suneela Mathe
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/ 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