Soft Skills

C Interview Questions and Answers for Freshers

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.

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.

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

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: