C Programming Interview Questions
C Language History, Basics & Program Structure
What is C?
C is a middle-level programming language developed by Dennis Ritchie at Bell Labs in 1972. It combines features of both high-level and low-level languages, making it suitable for system programming as well as application development.
Who developed C?
C was developed by Dennis Ritchie at Bell Laboratories (AT&T Bell Labs) between 1969 and 1973. It was originally created to develop the UNIX operating system.
What are the main features of C language?
Key features include: procedural programming, portability, modularity, efficiency, speed, extensibility, rich set of operators, pointers support, and direct memory access.
What is the basic structure of a C program?
A basic C program consists of: preprocessor directives (#include), global declarations, main() function (entry point), and function definitions.
What is the purpose of the main() function?
The main() function is the entry point of every C program. Execution begins from main() and ends when main() returns. It's mandatory in every C program.
What are header files in C?
Header files (with .h extension) contain function declarations, macro definitions, and constant definitions. They allow code reuse and modular programming. Common examples: stdio.h, stdlib.h, math.h.
What is the difference between compiler and interpreter?
A compiler translates the entire source code into machine code at once, creating an executable file. An interpreter translates and executes code line by line without creating a separate executable file.
What are keywords in C language?
Keywords are reserved words in C that have special meaning to the compiler. They cannot be used as identifiers (variable names, function names). Examples: int, float, if, else, while, for, return.
What is a token in C programming?
Tokens are the smallest individual units in a C program. They include keywords, identifiers, constants, string literals, operators, and special symbols that make up the program's syntax.
What is the purpose of comments in C program?
Comments are used to explain code, make it more readable, and help other programmers understand the logic. They are ignored by the compiler. Single-line comments use // and multi-line comments use /* */.
What is the purpose of the #include directive?
The #include directive is a preprocessor command that tells the compiler to include the contents of a specified file before compilation. It's used for including header files.
What is the difference between source code and object code?
Source code is the human-readable program written in C language. Object code is the machine-readable code generated by the compiler. Source code needs to be compiled into object code before execution.
What is the purpose of the preprocessor in C?
The preprocessor processes directives (commands starting with #) before actual compilation. It handles tasks like file inclusion (#include), macro expansion (#define), and conditional compilation (#ifdef, #ifndef).
What is an executable file in C?
An executable file is the final output of the compilation process that can be run directly by the operating system. It contains machine code that the computer's processor can execute.
What is the difference between printf() and scanf() functions?
printf() is used to output formatted data to the console (screen), while scanf() is used to input formatted data from the console (keyboard). Both are standard I/O functions from stdio.h library.
What is the difference between syntax error and logical error?
Syntax errors violate the grammatical rules of the C language and prevent compilation. Logical errors allow compilation and execution but produce incorrect results due to flawed algorithm or logic.
What is the purpose of the return statement in main()?
The return statement in main() returns an integer value to the operating system, indicating program termination status. Typically, 0 indicates successful execution, while non-zero values indicate errors.
What is the compilation process in C?
Compilation is the process of converting human-readable source code (C language) into machine-readable executable code. It involves preprocessing, compiling, assembling, and linking stages.
What are the different data types in C?
Basic data types: int, float, double, char. Derived data types: arrays, pointers, structures, unions. Void type: void.
What is the difference between = and == operators?
= is the assignment operator (assigns value to variable). == is the equality operator (compares two values for equality).
Note: These questions cover fundamental concepts of C programming. Understanding these basics is essential for any C programming interview.