C Interview Questions and Answers for Freshers

    1 Votes

54) What is size of void pointer?

Size of all pointers are same in C, regardless of their type because pointers variable holds a memory location. And for a given system, this size is constant. The type of pointer is used to know the size of the data that the pointer is pointer is pointing to.

55) What will be output of following program?
int main()
  int a = 260;
  char *ptr;
  ptr =( char *)&a;
  printf("%d ",*ptr);
  return 0;
(A) 2  (B) 260  (C) 4 (D) Compilation error  (E) None of above

Answer is B. 260 will take two byte memory space to reside and the bytes will be 1 and 4. Binary value of 260 is 00000001 00000100 (In 16 bit). So, ptr is only pointing to first 8 bit whose decimal value is 4.

56) What will be the output?

#include "stdio.h"
int main()
  char arr[100];
  printf("%d", scanf("%s", arr));
  /* Say the input is “hello” */
  return 1;

The scanf returns the number of inputs it has successfully read, so the output will be 1.

57) Guess the output.

#include <stdio.h>
int main()
  printf(6 + “Hello World”);
  return 0;

The printf is a library function which takes a char pointer as input. Here the pointer in incremented by 6, so the pointer will advance from pointing 'H' to 'W'. So the output will be “World”.

59) Guess the output?

#include <stdio.h>
int main()
  printf("%c ", 6[“Hello World”]);
  return 0;

In C, X[5] and 5[X] are the same. Here, 6[“Hello World”] will return the 6th element of the array “Hello World”, that is 'W'.

60) Guess the output?

#include <stdio.h>
  char *p = 0;
  *p = 'a';
  printf("value in pointer p is %c\n", *p);

a) It will print a b) It will print 0 c) Compile time error d) Run time error

Answer is d, runtime error. Because the pointer p is declared, but not the variable it is pointing to. In the statement, while assigning 'a', it will try to write in the address 0 and will get runtime error.

61) Which of the following is true

(A) gets() can read a string with newline chacters but a normal scanf() with %s can not.
(B) gets() can read a string with spaces but a normal scanf() with %s can not.
(C) gets() can always replace scanf() without any additional code.
(D) None of the above

Ans: (B)

62) What is the output of this C Program?

int main()
  printf("%d", printf("%d", 1234));
  return 0;

Answer is 12344. 1234 will be printed by the second printf and it will return 4 as printf returns the number of letters it printed.

63) How do you use a pointer to a function?

The hardest part about using a pointer-to-function is declaring it. Consider an example. You want to create a pointer, pf, that points to the strcmp() function. The strcmp() function is declared as shown below

int strcmp( const char *, const char * )

To set up “pf” to point to the strcmp() function, you want a declaration that looks just like the strcmp() function's declaration, but that has *pf rather than strcmp:

int (*pf)( const char *, const char * );

Notice that you need to put parentheses around *pf.

Page 7 of 8
Planning to do an MBA?
A quick all-in-one MBA entry manual for MBA Aspirants. Book covers
  • Possible MBA Tests & Exam Preparation
  • Tips to choose right MBA Program
  • Essay, Resume & Letter of Recommendation
  • MBA Interview Preparation
  • MBA Financial Planning
Price - 6.99$

Popular Videos

How to speak to people

How to speak so that people want to listen.

Got a tip or Question?
Let us know

Related Articles

C++ Interview Questions and Answers for Freshers, Experienced
Advanced C Interview Questions and Answers for Experienced
Embedded C Interview Questions and Answers