C Programming Interview Questions

Q1.   What is the use of main( ) in C?

main() function is the function from where execution of any C program begins. So, main() function is mandatory for any C program.

Q2.   What is the difference b/w include preprocessor using < and " ?
#include<filename> and #include"filename"?

  • The difference is in the location where the preprocessor searches for the included file.

  • For #include "filename" the preprocessor searches in the same directory as the file containing the directive. This method is normally used to include programmer-defined header files.

  • For #include < filename > the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

Q3.   What is the use of return value (int) of main function in C?

  • C's main function returns an int... that int goes to the program which executed it (the parent process, if you will) as an exit status code.

  • Specifically, on most operating systems, a 0 exit code signifies a normal run (no real errors), and non-zero means there was a problem and the program had to exit abnormally.

Q4.   What are header files and what are its uses in C programming?

  • Header files are also known as library files.

  • They contain the prototypes of functions being used in a program.

  • The file extension is .h

Q5.   What does the format %10.2 mean when included in a printf statement?

  • This format is used for two things: to set the number of spaces allotted for the output number and to set the number of decimal places.

  • The number before the decimal point is for the allotted space, in this case it would allot 10 spaces for the output number.

  • If the number of space occupied by the output number is less than 10, addition space characters will be inserted before the actual output number.

  • The number after the decimal point sets the number of decimal places, in this case, it?s 2 decimal spaces.

Q6.   What are reserved words/Keywords?

  • Reserved words are words that are part of the standard C language library.

  • This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for.

Q7.   What is data type in programming?

  • Data types in C language are defined as the data storage format that a variable can store a data to perform a specific operation.

  • Data types are used to define a variable before to use in a program.

  • Size of variable, constant and array are determined by data types.

Q8.   What is compiler?

  • Compiler is a program that converts human readable code into machine readable code. This process is called compilation.

Q9.   Difference between assembler, compiler and interpreter?

  • Assembler is a program that converts assembly level language (low level language) into machine level language.

  • Compiler compiles entire C source code into machine code.

  • Whereas, interpreters converts source code into intermediate code and then this intermediate code is executed line by line.

Q10.   What is variable initialization and why is it important?

  • This refers to the process wherein a variable is assigned an initial value before it is used in the program.

  • Without initialization, a variable would have an unknown value, which can lead to unpredictable outputs when used in computations or other operations.

Q11.   Difference between Source Codes and Object Codes?

  • Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do.

  • However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor.

  • In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ

Q12.   What is a newline escape sequence?

  • A newline escape sequence is represented by the \n character.

  • This is used to insert a new line when displaying data in the output screen.

  • More spaces can be added by inserting more \n characters.

Q13.   What is global variable in C?

  • The variables which are having scope/life throughout the program are called global variables.

  • Global variable is defined outside the main function. So, this variable is visible to main function and all other sub functions.

Q14.   What is local variable in C?

  • The variables which are having scope/life only within the function are called local variables.

  • These variables are declared within the function and can't be accessed outside the function.

Q15.   What is sizeof( ) function in C ?

  • sizeof() function is used to find the memory space allocated for each data type in C.

Q16.   Difference b/w auto and register variables ?

  • Storage class of all variables are auto by default unless we specify a variable is register or static or extern in C program.

  • Both auto variable and register variable are local variables.

  • Register variables are stored in register memory.

  • Whereas, auto variables are stored in main CPU memory.

Q17.   Difference b/w auto and static variables ?

  • Both auto and static variables are local variables.

  • Static variables can retain the value of the variable between different function calls.

Q18.   Difference b/w pre and post increment(++) operator ?

  • Pre increment operator is used to increment variable value by 1 before assigning the value to the variable.

  • Post increment operator is used to increment variable value by 1 after assigning the value to the variable.

Q19.   Difference b/w exit and return statements ?

  • exit(0); is a system call which terminates current process/program.

  • Whereas, return 0; is a C language instruction/statement and it returns from the current function.

Q20.   What is #define in C ?

  • #define is a pre-processor directive which is used to represent constant value.

  • This constant can be any of the basic data types and will replace by the value in the program at compile time..


(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017,, All rights reserved