C Interview Questions And Answers

What do you mean by the scope of a variable?
Scope indicates the region over which the variable's declaration has an effect.
What are the different types of scopes that a variable can have?
There are four types of scopes- file, function, block and prototype.  
What do you mean by definition of a variable?
In the definition of a variable, space is reserved for the variable and some initial value is given to it.
When we mention the prototype of a function, are we defining the function or declaring it?
When we mention the prototype of a function, we are declaring it.
What is C programming language?
C is a high level programming language which is developed by Dennis M. Ritchie.
Give some examples of software that is built using C language?
UNIX/ Linux Operating system, Databases, Text editors, language compilers.
Define C Compiler?
C compiler is used to convert human readable source code into machine language.
What is main() function in c?
Program execution begins from the main() function. Every C program must have a main() function. When we run a program, the operating system first looks at the main() function.
What are identifiers in C?
Identifiers are the name given to the variables, functions and constants. An identifier can start with A to Z, a to z, underscore (_) and followed by letters, numbers (0 to 9) or underscore(_).
Define keywords in C with examples?
Keywords are reserved words that cannot be used as a variable name, constant name and constant name. Examples - case, break, for , goto, void, do etc.
What is the sizeof operator?
sizeof operator is used to get the exact size of the variable.
What is void data type in c?
void is an empty datatype which is used in place where no value is returned. Like-

1. used with a function
void welcome(char *name)
printf("Welcome, %s.", name);

2. Used as function parameter - A function having no parameter can use void as parameter.
int rand(void);
Define enumerated data type in c?
An enumerated data type is an arithmetic data type that contains integral constants. Each constant is given a name and a value. Enum keyword is used to define enumerated data type.

enum location  {  east = 1, west = 2, north = 3, south = 4 };
What are the storage size of float and double?
Size of single precision float data type is 4 bytes and double precision float data type is 8 bytes.
Define constants in C?
Constants are fixed values that define only once and does not alter later. Constants can be any data types like an integer constants, floating constants etc.
What is a register storage class?
The register storage class is used to store variable values in CPU register. The value stored in a CPU register can be accessed faster than the one that is stored in memory.
How to include a file in a another file in c?
By using include statement, we can include one file into another.
Example - #include "filename"
What are the different types of linkages?
There are three different types of linkages - external, internal and none.
External linkage means global, non-static variables and functions.
Internal linkage means static variables and functions with file scope.
No linkage means local variables.
Define size_t?
size_t is used to express the size of something. It is the type of the result of the sizeof operator Or it is the type returned by strlen() to indicate the number of characters in a string.
Can we use a switch statement to switch on strings?
No, the cases in a switch must either have integer constants or constant expressions.
How floats are stored in binary form?
Floating point numbers are represented in IEEE format. The IEEE format for floating point storage uses a sign bit, a mantissa and an exponent for representing the power of 2. The sign bit denotes the sign of the number - a 0 represents a positive value and a 1 denotes a negative value. The mantissa is represented in binary after converting it to its normalised form.
Is it necessary that the header files should have a .h extensions?
No. It is not necessary.They have been given a .h extensions only to identify them as something different than the .c program files.
What do the header files usually contain?
Header files contain pre-processor directives like #define, structure, union and enum declarations, typedef declarations, global variable declarations and external function declarations.
Will it result into an error if a header file is included twice?
Yes, unless the header file has taken care to ensure that if already included doesn't get included again.
On doing #include where are the header files searched?
If #included using < > the files get searched in the predefined include path. It is possible to change the predefined include path. If #include with the "" syntax in addition to the predefined include path the files also get searched in the current directory.
Are the expressions *ptr++ and ++*p same?
No, *ptr++ increments the pointer and not the value pointed by it, whereas ++*ptr increments the value being pointer to by ptr.
For which purpose, we can use pointers?
We can use pointer in lot of places, like -
Accessing array or string elements
Dynamic memory allocation
Call by reference
Implementing linked lists, trees, graphs and many other data structures.
What is null pointer?
For each pointer type, C defines a special pointer value. If a pointer is initialized with a NULL value, is considered as NULL Pointer.
What is NULL macro?
A NULL macro is used to represent the null pointer in source code. It has a value 0 associated with it.
What is ASCII NUL character?
The ASCII NUL character has all its bits as 0 but doesn't have any relationship with the null pointer.
How many bytes are occupied by near, far and huge pointers?
A near pointer is 2 bytes long whereas a far and a huge pointer are 4 bytes long. Note the near, far and huge pointers exist only under DOS. Under Windows and Linux every pointer is 4 bytes long.
Is the NULL pointer same as an uninitialised pointer?
In which header file is the NULL macro defind?
In "stdio.h" and "stddef.h" files.
How many array elements can be designate in expression num[45]?
Which library function is used to reverse a string?
strrev() function is used to reverse a string.
Which library function is used to find the last occurrence of a character in a string?
strchr() function is used to find the last occurrence of a character in a string.
How are structure passing and returning by the compiler?
When structures are passed as arguments to functions, the entire structure is pushed on the stack. To return structures a hidden argument generated by the compiler is passed to the function. This argument points to a location where the returned structure is copied.
What is the difference between a structure and a union?
In a union, complier allocates memory for the largest of all the members whereas in structure all the members get allocated memory.
What is the difference between an enumeration and a set of preprocessor #defines?
The #define has a global effect, whereas an enumeration can have an effect local to the block, if desired.
Which function is more safe to use, fgets() and gets()?
fgets(), because unlike fgets(), gets() cannot be told the size of the buffer into which the string supplied will be stored. As a result, there is always a possiblility of overflow of buffer.
Which bitwise operator is suitable for turning off a particular bit in a number?
The & operator.
How will you use calloc() functions?
calloc() needs two arguments, the number of elements to be allocated and the size of each element.


p = (int*) calloc(10, sizeof(int));

The above example allocate space for a 10-integer array.

Which function should be used to free the memory allocated by calloc()?
free() function should be used to free the memory allocated by calloc().
What is Include directive?
The ‘include’ directive is used to make the inclusion of any header file available to the C program. It causes the preprocessor to add the contents of the corresponding header file to the program where you have written include statement.
Define Keywords?
Keywords are the reserve words whose meaning has been already explained to the compiler. The keywords can not be used as a variable names. Example – float, case, return, void, while
What is constants?
A constant is an entity that does not changed the value at run time.
What is variables?
Variable is an identifier, which is used to store a data values for processing. A variable can have different data values at different times during program execution.
What is local variable?
Local variable are declared inside a function, and can be used only inside that function. It is possible to have local variables with the same name in different functions.
What is global variable?
Global variable are declared outside any function and they can be accessed on any function in the program.
What is stdio.h?
The header files named ‘stdio.h’ has the collection of input/output functions. These functions are associated with keyword input/file input and screen output/file output.
What is scanf() function?
scanf() is a library functions. It is used to receive values of variables from keyboard.
What is conio.h?
conio.h header file contains functions for console input/output in C programming. Functioning of conio.h can be used to clear screen, change color of text and background.
What is Goto Statement?
This is an unconditional control statement that transfers the flow of control to another part of the program.
What is getch()?
This function gets a character from console but does not echo it to the screen. When getch() occurs in a program, it indicates the program waits for user input and when user presses any key, the execution of program continue.
Define clrsrc()?
This is a library function to clear the output screen. It is pre-defined function in header file conio.h.
Define switch statement?
This is a multidirectional conditional control statement. Sometimes there is a need in program to make choice among number of alternatives. For making choice, we use the switch statement.
What is Call by Value?
In this method the value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function.
What is Call by Reference?
In this method, the addresses of actual arguments in the calling function are copied into the formal arguments of the called function. It means, using these addresses, we would have an access to the actual arguments.
What is recursion?
A function is called recursive if a statement within the body of the function calls the same function. Recursion is the process defining something in terms of itself.
What is the difference between the function rewind() and fsetpos()?
rewind() function repositions file pointer to streams beginning. fsetpos() positions the file pointer of a stream at the desired position.

Read more articles

General Knowledge

Learn Popular Language