Answers To Some Tricky C Programming Interview Questions

Interviews always create some tensed situation and to make you feel easy about them, here we share some commonly asked C programming interview questions during an interview for C programming. And also shared the best suitable answers from the internet sources.

C programming interview questions and answers:

Differentiate between declaration and definition of a variable or function?

Declaration of a variable or function says that the variable or function is present in the program but the memory is not for them. Whereas, the declaration of a variable or function plays an important role. When a variable is told, the program is sure about the data type of that variable. While for function declaration, the program knows about the arguments to the functions, their data varieties, the order of arguments and return kind of function. What is all about declaration? As per definition, when a variable/function is defined, besides the role of the declaration, it also has memory for the same.

Name the various storage class specifiers in C?

Auto, register, static, extern

What is the scope of a variable? How are variables scoped in C?

The scope of a variable is a section of the program where the variable might directly be accessible.

How to print “Hello World” without semicolon?

int main(void)

{

if (printf(“Hello World”)) ;

}

Why use pointers in a C program?

1. To get a variable address

2. To attain pass by reference in C

3. To pass huge structures to avoid ditto copy of the structure.

4. To put “linked” data structures similar to linked lists and binary trees.

Define NULL pointer?

NULL indicates that the pointer is not pointing at a valid location. Mainly we need to initialize pointers as NULL if their value is not known at the time of declaration.

Define Dangling pointer?

They do not point to a valid memory location. They happen when an object gets deleted or dislocated, without modification of the value of the pointer, such that the pointer yet points to a memory location.

Define memory leak. Why it is to be avoided?

This takes place when programmers develop a memory and forgets to delete it. Memory leaks are a serious concern for programs like daemons and servers do not terminate.

Define local static variables?

The life of such variable does not end with a function call where it got declared. It extends for the whole lifetime of a complete program. They are used to count the number of times a function is called. Also, they get the default value as 0.

Define static functions?

In C, functions are the default. The “static” word ahead of a function makes it static. Sometimes we want to restrict some functions which will be used later if we want ar that time using static before function will do the work.

With this, we conclude. Hope the above C programming interview questions and answers would help you. And keep looking into this space by career advice for more career guidance tips, news, and updates.

Leave your thoughts