• admin@embedclogic.com

C Interview Questions

1. Why is the c language so popular even today?

Although there are various languages nowadays C still maintains it’s position over other languages due to some of its unique features. Some of the features are mentioned below-

— Portability: Cross-platform portability of program with minimal changes.

— Simple and Efficient: High-level language feature support makes it programmer-friendly as well as it is very close to the low level(assembly) which makes it fast.

— Memory Manipulation: Arbitrary memory address access and pointer arithmetic is an important feature that makes C a perfect fit for operating systems and embedded systems.

2. What is the Command line argument in C?

Command line argument is basically input parameters of the main function in C and it is used when user need to pass input from outside(terminal) in program

argc = Supplied argument count.

argv[0] = Program executable.
argv[1]= First Input Parameter supplied in main from the terminal.
argv[2]= Second Input Parameter in supplied in main from terminal.

Example:

argv[0]=test

argv[1]=”Amit”

argc=2

3. What are the compilation stages?

There are 4 stages involved in the creation of an executable file from the source. files.

— Pre-processing

— Compilation

— Assemble

— Linking

For detail about all stages click here

4. What is storage Class in C?

Storage class decides the memory allocation for a variable, it’s scope and visibility in a program. There are 4 storage classes in C-

Storage ClassExamplestorage in MemoryScopeVisibility
autoauto int x;stackonly in block where it is declared.only in block where it is declared.
registerregister int x;CPU Registeronly in block where it is declared.only in block where it is declared.
staticstatic int x;
static int x=10;
static int x;-
Uninitialized Data Segment
static int x=10;
Initialized Data segment
In whole file where it is declaredonly inside block or file where it is declared.
externextern int x;initialized Data segmentin whole programin whole program
5. What is static and extern storage class in C?
  • Static Storage Class

A variable declared with static keyword is-

— Only accessible within the file(Global static variable) or block(local static variable) where it is declared.

— Global Static variable or function can not be access outside the file.

— Static variable whether it is global or local default value will be zero.

— static variable initialize only once whether it is local or global.

run the above program;

xlocal=0 —> when test function call first then it will print default value of static variable xlocal.

xlocal =1—-> when test function calls the second time then it will not re-initialize and print the updated value from last function call.

  • extern storage class?

extern keyword is used to declare global variable or function which is

— accessible outside the file.

You can see globalExternVarX is declared in test1.c and defined in test2.c. while it’s definition in test2.c but it can be used in test1.c because it is declared as an extern variable.

— Not occupy any memory until it is not initialized but initialization must be only once in the whole program.

–extern variable could not be initialized inside function.

6. What is Call by value and Call by reference in C?

Call by value- Function calling in which input argument is variable or constant.

Call by reference- Function calling in which input argument is the address of the variable.

7. What is recursion?

recursion is the process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function.

Example : factorial programming

5! = 5*4! = 5*4*3! = 5*4*3*2! = 5*4*3*2*1! = 5*4*3*2*1

In the above example, to get factorial of 5 you can see factorial function (!) calls itself again and again with a different value(5,4,3,2,1). This process is called recursion and function are known as a recursive function.More

8. what is the use of typedef?

typedef is used for alias name to the standard datatypes.

Suppose you want to give an alias name uint32_t and uint8_t to the standard data type unsigned int and unsigned char.then you have to write this code in your project.

Example

9. How does #define differ from typedef?

— typedef is used to give alias name to standard data type while #define is exact replacement of words.

— typedef terminate with semicolon while #define work without semicolon.

— typedef statement processed during compilation while the #define process in the pre-processing stage.