C Programming Interview QuestionsA list of 50 top frequently asked C programming interview questions and answers are given below. 1) What is C language?C is a mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation. More details. 2) Why is C known as a mother language?C is known as a mother language because most of the compilers and JVMs are written in C language. Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages. More details. 3) Why is C called a mid-level programming language?C is called a mid-level programming language because it binds the low level and high -level programming language. We can use C language as a System programming to develop the operating system as well as an Application programming to generate menu driven customer driven billing system. More details. 4) Who is the founder of C language?Dennis Ritchie. More details. 5) When was C language developed?C language was developed in 1972 at bell laboratories of AT&T. More details. 6) What are the features of the C language?The main features of C language are given below:
7) What is the use of printf() and scanf() functions?printf(): The printf() function is used to print the integer, character, float and string values on to the screen. Following are the format specifier:
scanf(): The scanf() function is used to take input from the user. More details.8) What is the difference between the local variable and global variable in C?Following are the differences between a local variable and global variable:
9) What is the use of a static variable in C?Following are the uses of a static variable:
10) What is the use of the function in C?Uses of C function are:
11) What is the difference between call by value and call by reference in C?Following are the differences between a call by value and call by reference are:
Example of call by value: Output: Value of a is: 10 Value of b is: 20 Example of call by reference: Output: Value of a is: 13 Value of b is: 17 12) What is recursion in C?When a function calls itself, and this process is known as recursion. The function that calls itself is known as a recursive function. Recursive function comes in two phases:
Winding phase: When the recursive function calls itself, and this phase ends when the condition is reached. Unwinding phase: Unwinding phase starts when the condition is reached, and the control returns to the original call. Example of recursion Output: factorial of a number is 120 13) What is an array in C?An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration. Arrays are of two types:
Syntax:
Syntax: Example of an array: Output: 1 2 3 4 5 14) What is a pointer in C?A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast. Whenever a variable is declared inside a program, then the system allocates some memory to a variable. The memory contains some address number. The variables that hold this address number is known as the pointer variable. For example: The above syntax tells that p is a pointer variable that holds the address number of a given data type value. Example of pointer Output: Address value of 'a' variable is 428781252 15) What is the usage of the pointer in C?
16) What is a NULL pointer in C?A pointer that doesn't refer to any address of value but NULL is known as a NULL pointer. When we assign a '0' value to a pointer of any type, then it becomes a Null pointer. 17) What is a far pointer in C?A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given section. 18) What is dangling pointer in C?
Let's see this through an example. In the above example, initially memory is allocated to the pointer variable ptr, and then the memory is deallocated from the pointer variable. Now, pointer variable, i.e., ptr becomes a dangling pointer. How to overcome the problem of a dangling pointer The problem of a dangling pointer can be overcome by assigning a NULL value to the dangling pointer. Let's understand this through an example: In the above example, after deallocating the memory from a pointer variable, ptr is assigned to a NULL value. This means that ptr does not point to any memory location. Therefore, it is no longer a dangling pointer. 19) What is pointer to pointer in C?In case of a pointer to pointer concept, one pointer refers to the address of another pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains the address of a variable. The pointer to pointer contains the address of a first pointer. Let's understand this concept through an example: In the above example, pptr is a double pointer pointing to the address of the ptr variable and ptr points to the address of 'a' variable. 20) What is static memory allocation?
The above example creates an array of integer type, and the size of an array is fixed, i.e., 10. 21) What is dynamic memory allocation?
The above example allocates the memory at runtime. 22) What functions are used for dynamic memory allocation in C language?
Syntax Syntax Syntax In the above syntax, ptr is allocated to a new size. Syntax The above syntax releases the memory from a pointer variable ptr. 23) What is the difference between malloc() and calloc()?
24) What is the structure?
Syntax of structure Let's see a simple example. Output: Enter the name shikha Enter the age 26 Name and age of a student: shikha,26 25) What is a union?
Syntax of union Let's see a simple example Output: value of a is 1085485921 value of b is 5.600022 value of ch is a In the above example, the value of a and b gets corrupted, and only variable ch shows the actual output. This is because all the members of a union share the common memory space. Hence, the variable ch whose value is currently updated. 26) What is an auto keyword in C?In C, every local variable of a function is known as an automatic (auto) variable. Variables which are declared inside the function block are known as a local variable. The local variables are also known as an auto variable. It is optional to use an auto keyword before the data type of a variable. If no value is stored in the local variable, then it consists of a garbage value. 27) What is the purpose of sprintf() function?The sprintf() stands for "string print." The sprintf() function does not print the output on the console screen. It transfers the data to the buffer. It returns the total number of characters present in the string. Syntax Let's see a simple example Output: value of n is 9 28) Can we compile a program without main() function?Yes, we can compile, but it can't be executed. But, if we use #define, we can compile and run a C program without using the main() function. For example: 29) What is a token?The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest individual unit in a program. C has the following tokens:
30) What is command line argument?The argument passed to the main() function while executing the program is known as command line argument. For example: 31) What is the acronym for ANSI?The ANSI stands for " American National Standard Institute." It is an organization that maintains the broad range of disciplines including photographic film, computer languages, data encoding, mechanical parts, safety and more. 32) What is the difference between getch() and getche()?The getch() function reads a single character from the keyboard. It doesn't use any buffer, so entered data will not be displayed on the output screen. The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character. Let's see a simple example Output: Enter a character value of ch is a Enter a character again a value of ch is a In the above example, the value entered through a getch() function is not displayed on the screen while the value entered through a getche() function is displayed on the screen. 33) What is the newline escape sequence?The new line escape sequence is represented by "\n". It inserts a new line on the output screen. More details.34) Who is the main contributor in designing the C language after Dennis Ritchie?Brain Kernighan. 35) What is the difference between near, far and huge pointers?A virtual address is composed of the selector and offset. A near pointer doesn't have explicit selector whereas far, and huge pointers have explicit selector. When you perform pointer arithmetic on the far pointer, the selector is not modified, but in case of a huge pointer, it can be modified. These are the non-standard keywords and implementation specific. These are irrelevant in a modern platform. 36) What is the maximum length of an identifier?It is 32 characters ideally but implementation specific. 37) What is typecasting?The typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly. Syntax 38) What are the functions to open and close the file in C language?The fopen() function is used to open file whereas fclose() is used to close file. 39) Can we access the array using a pointer in C language?Yes, by holding the base address of array into a pointer, we can access the array using a pointer. 40) What is an infinite loop?A loop running continuously for an indefinite number of times is called the infinite loop. Infinite For Loop: Infinite While Loop: Infinite Do-While Loop: 41) Write a program to print "hello world" without using a semicolon?More details.42) Write a program to swap two numbers without using the third variable?More details.43) Write a program to print Fibonacci series without using recursion?More details.44) Write a program to print Fibonacci series using recursion?More details.45) Write a program to check prime number in C Programming?More details.46) Write a program to check palindrome number in C Programming?More details.47) Write a program to print factorial of given number without using recursion?More details.48) Write a program to print factorial of given number using recursion?More details.49) Write a program to check Armstrong number in C?More details.50) Write a program to reverse a given number in C?More details. |