Sei sulla pagina 1di 5

C Programming Viva Question

1.

Comment on the following?


const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) Both (a) and (b)
d) You can change the pointer as well as the value pointed by it

2.

Comment on the following pointer declaration?


int *ptr, p;
a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is a pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer

3.

What is the output of this C code?

1.

#include <stdio.h>

2.

int *f();

3.

int main()

4.

5.

int *p = f();

6.

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

7.

8.

int *f()

9.

10.

int j = 10;

11.

return &j;

12.

}
a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behavior

4. What is the output of this C code?


1.

#include <stdio.h>

2.

int main()

3.

4.

int i = 10;

5.

void *p = &i;

6.

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

7.

return 0;

8.

}
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour

5. How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits.
6. What is the output of this C code?
1.

#include <stdio.h>

2.

void main()

3.

4.

int a[3] = {1, 2, 3};

5.

int *p = a;

6.

int **r = &p;

7.

printf("%p %p", *r, a);

8.

a) Different address is printed


b) 1 2
c) Same address is printed.
d) 1 1
7. Which of the following return-type cannot be used for a function in C?
a) char *
b) struct
c) void
d) None of the mentioned
8. FILE is of type ______ ?
a) int type
b) char * type
c) struct type
d) None of the mentioned
9. What is the meant by a in the following operation?
fp = fopen(Random.txt, a);
a) Attach
b) Append
c) Apprehend
d) Add
10. Which type of files cant be opened using fopen()?
a) .txt
b) .bin
c) .c
d) None of the mentioned

11. Which is true about getc.getc returns?


a) The next character from the stream referred to by file pointer
b) EOF for end of file or error
c) Both a & b
d) Nothing.

12. Which of the following fopen statements are illegal?


a) fp = fopen(abc.txt, r);
b) fp = fopen(/home/user1/abc.txt, w);
c) fp = fopen(abc, w);
d) None of the mentioned
13. FILE reserved word is
a) A structure tag declared in stdio.h
b) One of the basic datatypes in c
c) Pointer to the structure defined in stdio.h
d) It is a type name defined in stdio.h

14. What is the output of this C code?


1.

#include <stdio.h>

2.

int main()

3.

4.

FILE *fp = stdin;

5.

int n;

6.

fprintf(fp, "%d", 45);

7.

}
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard

15. What is the output of this C code?


1.

#include <stdio.h>

2.

#include <stdlib.h>

3.

int main()

4.

5.

FILE *fp = stdout;

6.

int n;

7.

fprintf(fp, "%d", 45);

8.

}
a) Compilation error
b) 45
c) Nothing
d) Depends on the standard

16. stdout, stdin and stderr are


a) File pointers
b) File desciptors
c) Streams
d) Structure