Sunteți pe pagina 1din 14

C/C++ Interview questions

1. Identify which of the following are declarations

1 : extern int x;

2 : float square ( float x ) { ... }

3 : double pow(double, double);

A. 1 B. 2 C. 1 and 3 D. 3

2. We want to round off x, a float, to an int value, The correct way to do is

A. y = (int)(x + 0.5) B. y = int(x + 0.5) C.y = (int)x + 0.5

D. y = (int)((int)x + 0.5)

3. Can you combine the following two statements into one?

char *p; p = (char*) malloc(100);

A. char p = *malloc(100); B. char *p = (char) malloc(100);

C. char *p = (char*)malloc(100); D. char *p = (char *)(malloc*)(100);

4. What would be the equivalent pointer expression for referring the array element
a[i][j][k][l]

A. ((((a+i)+j)+k)+l) B. *(*(*(*(a+i)+j)+k)+l) C. (((a+i)+j)+k+l) D.


((a+i)+j+k+l)
5. In which header file is the NULL macro defined?

A. stdio.h B. stddef.h C. stdio.h and stddef.h D. stdlib.h

6. How will you free the allocated memory ?

A. remove(var-name); B. free(var-name);

C. delete(var-name); D. dalloc(var-name);

7. In which numbering system can the binary number 1011011111000101 be easily


converted to?

A. Decimal system B. Hexadecimal system C. Octal system D. No need to


convert

8. Which bitwise operator is suitable for turning off a particular bit in a number?

A. && operator B. & operator C. || operator D.! operator

9. What is the output of the following prog?

.#include<stdio.h>

#include<stdlib.h>

#define MAXROW 3

#define MAXCOL 4

int main()

{ int **p, i, j;

p = (int **) malloc(MAXROW * sizeof(int*));


return 0;

A. memfree(int p); B. dealloc(p); C. malloc(p, 0); D. free(p);

10. What function should be used to free the memory allocated by calloc() ?

A. dealloc(); B. malloc(variable_name, 0) C. free(); D.


memalloc(variable_name, 0)

11. What will the function rewind() do?

A. Reposition the file pointer to a character reverse.

B. Reposition the file pointer stream to end of file.

C. Reposition the file pointer to beginning of that line.

D. Reposition the file pointer to beginning of file.

12. What is the purpose of fflush() function.

A. flushes all streams and specified streams. B. flushes only specified stream.

C. flushes input/output buffer. D. flushes file buffer.

13. How many times "TechnoVeta" is printed?

#include<stdio.h>

int main()

int x;
for(x=-1; x<=10; x++)

if(x < 5)

continue;

else

break;

printf("TechnoVeta");

return 0;

A. Infinite times B. 11 times C. 0 times D. 10 times

14.How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>

int main()

int j=1;

while(j <= 255)

printf("%c %d\n", j, j);

j++;
}

return 0;

A. Infinite times B. 255 times C. 256 times D. 254 times

15. What is the notation for following functions?

1. int f(int a, float b)

/* Some code */

2. int f(a, b)

int a; float b;

/* Some code */

A) 1. KR Notation 2. ANSI Notation B) 1. Pre ANSI C Notation 2. KR


Notation

C. 1. ANSI Notation 2. KR Notation D. 1. ANSI Notation 2. Pre ANSI


Notation
16. The keyword used to transfer control from a function back to the calling function is

A. switch B. goto C. go back D. return

17. What will happen if in a C program you assign a value to an array element whose
subscript exceeds the size of array?

A. The element will be set to 0.

B. The compiler would report an error.

C. The program may crash if some important data gets overwritten.

D. The array size would appropriately grow.

18. What does fp point to in the program ?

#include<stdio.h>

int main()

FILE *fp;

fp=fopen("trial", "r");

return 0;

A. The first character in the file

B. A structure which contains a char pointer which points to the first character of a file.

C. The name of the file.

D. The last character in the file.


19. In a file contains the line "I am a boy\r\n" then on reading this line into the array str
using fgets(). What will str contain?

A. "I am a boy\r\n\0" B. "I am a boy\r\0" C. "I am a boy\n\0" D. "I am a


boy"

20. To print out a and b given below, which of the following printf() statement will you
use?

#include<stdio.h>

float a=3.14;

double b=3.14;

A. printf("%f %lf", a, b); B. printf("%Lf %f", a, b);

C. printf("%Lf %Lf", a, b); D. printf("%f %Lf", a, b);

21. What is x in the following program?

#include<stdio.h>

int main()

typedef char (*(*arrfptr[3])())[10];

arrfptr x;

return 0;

}
A. x is a pointer B. x is an array of three pointers

C. x is an array of three function pointers D. Error in x declaration

22. In the following code what is 'P'?

typedef char *charp;

const charp p;

A. P is a constant B. P is a character constant C. P is character type D. None of


above

23. In the following code, the P2 is Integer Pointer or Integer?

typedef int *ptr;

ptr p1, p2;

A. Integer B. Integer pointer C. Error in declaration D. None of above

24. What will be the output of the program?

#include<stdio.h>

#include<stdarg.h>

void fun(char *msg, ....);

int main()

{
fun("TechnoVeta", 1, 4, 7, 11, 0);

return 0;

void fun(char *msg, ....)

int tot=0;

va_list ptr;

int num;

va_start(ptr, msg);

num = va_arg(ptr, int)

num = va_arg(ptr, int)

printf("%d", num);

A. TechnoVeta 1 7 11 0 B. 1 C. 4 D. 7

25. What is the output of the following program?

#include<stdio.h>

#include<stdarg.h>

void dumplist(int, ...);

int main()

{
dumplist(2, 4, 8);

dumplist(3, 6, 9, 7);

return 0;

void dumplist(int n, ...)

va_list p; int i;

va_start(p, n);

while(n -> 0)

i = va_arg(p, int);

printf("%d", i);

va_end(p);

A. B C D
24 248 48 111

36 3, 6, 9, 7 697 1111

26. In which stage does the following code

#include<stdio.h>

get replaced by the contents of the file stdio.h?


A. During editing B. During linking C. During execution D.
During preprocessing

27. What will the SWAP macro in the following program be expanded to on
preprocessing? will the code compile?

#include<stdio.h>

#define SWAP(a, b, c)(c t; t=a, a=b, b=t)

int main()

int x=10, y=20;

SWAP(x, y, int);

printf("%d %d\n", x, y);

return 0;

A. It compiles B. Compiles with a warning C. Not compile D. Compiles and print


nothing

28. The library function used to reverse a string is

A. strstr() B. strrev() C. revstr() D. strreverse()

29. If the two strings are identical, then strcmp() function returns

A. -1 B. 1 C. 0 D. Yes
30. The maximum combined length of the command-line arguments including the spaces
between adjacent arguments is

A. 128 characters B. 256 characters

C. 67 characters D. It may vary from one operating system to another

31. What would be the output of the following program?

#include<stdio.h>

int get();

int main()

const int x = get();

printf("%d", x);

return 0;

int get()

return 20;

A. Garbage value B. Error C. 20 D. 0

32. What would be the output of the following program?

#include<stdio.h>

int main()
{

const char *s = "";

char str[] = "Hello";

s = str;

while(*s)

printf("%c", *s++);

return 0;

A. Error B. H C. Hello D. Hel

33. In the statement char **argv;

A. argv is a pointer to pointer. B. argv is a pointer to a char pointer.

C. argv is a function pointer. D. argv is a member of function pointer

34. What does the following declaration signify?

void (*cmp)();

A. cmp is a pointer to a void function type.

B. cmp is a void type pointer function.

C. cmp is a function that returns a void pointer.

D. cmp is a pointer to a function which returns void


35. What is the best C statement that does this?

"A pointer to a function which receives nothing and returns nothing"

A. void *(ptr)*int; B. void *(*ptr)() C. void *(*ptr)(*) D. void (*ptr)()

S-ar putea să vă placă și