Tuesday 11 December 2012

C interveiw questions with answers

Placement stuff..

printf() Function- What is the difference between "printf(...)" and
"sprintf(...)"?

sprintf(...) writes data to the character array whereas printf(...) writes data to the
standard output device.

Compilation How to reduce a final size of executable?
Size of the final executable can be reduced using dynamic linking for
libraries.

Linked Lists -- Can you tell me how to check whether a linked list is circular?

Create two pointers, and set both to the start of the list. Update each
as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}
}
If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, its either 1 or 2 jumps until they meet.

What are the different storage classes in C?
C has three types of storage: automatic, static and allocated. Variable having block scope and without static specifier have automatic storage duration. Variables with block scope, and with static specifier have static scope. Global variables (i.e, file scope) with or without the static specifier also
have static scope. Memory obtained from calls to malloc(), alloc() or realloc() belongs to
allocated storage class.

No comments:

Post a Comment