Top Basic C Interview Question and Answer 2023

Updated:01/01/2023 by shubham mishra
The versatility of the C programming language's use for memory management is one of the factors contributing to its popularity.
Therefore C language use in hardware software for PC or Laptop. Programmers have the ability to decide how, when, and where memory is allocated and deallocated. In the C programming language, memory is allocated statically, automatically, or dynamically.
Top 50 C Interview Question and answer

Q.1 Differentiate between Actual Parameters and Formal Parameters.
Ans.The Parameters which are sent from main function to the subdivided function are called as Actual Parameters and the parameters which are declared a the Subdivided function end are called as Formal Parameters.

Q.2 Can a C program be compiled or executed in the absence of a main()?
Ans.The program will be compiled but will not be executed. To execute any C program, main() is required.

Q.3 What do you mean by a Nested Structure?
Ans. When a data member of one structure is referred by the data member of another function, then the structure is called a Nested Structure.

Q.4 What is the main difference between the Compiler and the Interpreter?
Ans.Compiler is used in C Language and it translates the complete code into the Machine Code in one shot. On the other hand, Interpreter is used in Java Programming Langauge and other high-end programming languages. It is designed to compile code in line by line fashion.

Q.5 What is a C Token?
Ans. TOKEN is the smallest unit in a 'C' program. It is each and every word and punctuation that you come across in your C program. The compiler breaks a program into the smallest possible units (tokens) and proceeds to the various stages of the compilation. A token is divided into six different types, viz, Keywords, Operators, Strings, Constants, Special Characters, and Identifiers.

Q.6 What is the purpose of printf() and scanf() in C Program?
Ans. printf() is used to print the values on the screen. To print certain values, and on the other hand, scanf() is used to scan the values. We need an appropriate datatype format specifier for both printing and scanning purposes. For example,

Q.7 Can I create a customized Head File in C language?
Ans. It is possible to create a new header file. Create a file with function prototypes that need to be used in the program. Include the file in the ‘#include’ section in its name.

Q.8 What is typecasting?
Ans. 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:
(type_name) expression;

Q.9 Write a C program to print hello world without using a semicolon (;)
Ans. #include < stdio.h >
void main()
if(printf('hello world')){}

Q.10 What do you mean by Dangling Pointer Variable in C Programming?
Ans. A Pointer in C Programming is used to point the memory location of an existing variable. In case if that particular variable is deleted and the Pointer is still pointing to the same memory location, then that particular pointer variable is called as a Dangling Pointer Variable.

Ans. Arithmetic operators
Assignment operators
Relational operators
Logical operators
Bit wise operators
Conditional operators (ternary operators)
Increment/decrement operators
Special operators

Q.12 Write prgram of C Code with Macros
Ans. #define SQUARE(x) ((x)*(x))
void test() {
int x = 5;
int y = SQUARE(x++);
printf('Result of x is %d, y is %d. ', x, y);

Q.13 Write program using C Code to Allocate Memory.

char* allocateMemory() {
char str[20] = 'Hello are you with us.';
return str;
void test() {
char* pString = allocateMemory();
printf('pString is %s. ', pString);

Q14. What will be printed as the result of the operation below?
char *p1;
char *p2;
Ans. Output: Ciscosystems

Q15. What will be output of following program?

int main() {
int a = 10;
void *p = &a;
int *ptr = p;
return 0;
Ans. Output: 10

Q16. State the equivalent pointer expression which refer the given array element
Ans. Above pointer expression can be written as *(*(*(*(a+i)+j)+k)+l).

Q17. Can you combine the following two statements into one?
char *p;
p = (char*)malloc(100);
Ans. Above two expressions can be written in combined form aschar*p = (char*)malloc(100);

Q.18 Difference between of printf() and scanf() functions?
Ans .printf() is used to print the output on the display.
scanf() is used to read formatted data from the keyboard.
Some datatype format specifiers for both printing and scanning purposes are as follows:

Q.19 What is format specifiers?
%d: It's a datatype format specifier for printing and scanning an integer value.
%s: It's a datatype format specifier for printing and scanning a string.
%c: It's a datatype format specifier for displaying and scanning a character value.
%f: The datatype format specifier %f is used to display and scan a float value

Q.20 What is typecasting in C?
Ans. Typecasting is the process to convert a variable from one datatype to another. If we want to store the large type value to an int type, then we will convert the data type into another data type explicitly.

Q.21 Why n++ executes faster than n+1 ?
Ans .n++ being a unary operation, it just needs one variable. Whereas, n = n + 1 is a binary operation that adds overhead to take more time (also binary operation: n += 1). However, in modern platforms, it depends on few things such as processor architecture, C compiler, usage in your code, and other factors such as hardware problems.

Q.22 What are Enumerations?
Ans. Enumeration, also known as Enum in C, is a user-defined data type. It consists of constant integrals or integers that have names assigned to them by the user. Because the integer values are named with enum in C, the whole program is simple to learn, understand, and maintain by the same or even different programmer.

Q.23 what is meaning of char* p ?
Ans. const char* p is a pointer to a const char.

Note: const char and char const are the same.

Q.24 what is meaning of char const* p ?
Ans. char const* p is a pointer to a char const. Note: const char and char const are the same.

Q.25 What is the difference between ‘g’ and “g” in C?
Ans.In C double-quotes variables are identified as a string whereas single-quoted variables are identified as the character.

Q.26 What is global variable.
Ans .The difference between this is in scope. A truly global variable has a global scope and is visible everywhere in your program.
int my_global_var = 0;
printf('%d ', my_global_var);
return 0;

  1. Is the statement within the if construct given below executed? Why or why not?
  2. write a program to accept a string and an integer, and print the string as many times as the value of the integer this procedure should continue until the user presses q to quit ?
  3. Explain the difference between while and do while loops with respect to the minimum number of times the body of the loop is executed.
  4. write a program that accepts a number from 0 to 9 along with a string to be displayed a specified number of times. Use the switch case construct. ?
  5. write a program to accept characters until q is pressed Display each character immediately after it is accepted. Also store the characters in an array, to be displayed before the program terminates.
  6. Explain the significance of the break statement in the switch case construct what would result in its absence?
  7. write a program that accepts 0, 1, or 2 if 0 is entered by the user, accept the necessary parameters (radius height, etc.) to calculate the volume of a cylinder inputs 1 and 2 correspond to cylinder and cone, respectively. Note that the above process must go on until the user enters q to terminate the program [Hint: use a switch – case construct within a while or do – while loop]
  8. when is the default keyword useful in a switch – case construct? Modify the program written for question 6 so that an error message is displayed whenever an input other than 0, 1 or 2 is entered.
  9. modify the sample programs given in this chapter by replacing a while – loop by a for – loop and vice- versa?
  10. write a program to generate the first hundred tems of the Fibonacci series and print their sum and average?
  11. why do you think the use of the go to statement is generally discouraged? Under what conditions are they specially useful?
  12. Write a program that determines whether or not the input string is a palindrome.
  13. write a program to input a string, sum up the ASCII values of all its character, and output the resulting value. Use a single loop?
  14. (Hint : use the getchar function to read the input character by character and test for for the newline)
  15. what is the output of the following statements:
  16. for ( I = 0; I< 10 ; I ++); 
    printf ( “% d / n “ , I ); 
    ( Hint : notice the semicolon at the end of the for construct) 
  17. write the output of the following statements:
  18. for ( i = 10; i ++; i< 100) 
     printf ( “ % d / n “ , i ); 
    ( To understand the output better, make i an unsigned char)