C Programming Interview Questions

Why C is called a mid level programming language?

It supports the feature of both low-level and high-level languages that is why it is known as a mid level programming language.

What is Local variable and Global variable?

Local variable: A variable which is declared inside function or block is known as a local variable.

Global variable: A variable which is declared outside function or block is known as a global variable.

Example:

int a=10; // Global variable
void main()
{
int b=20 //Local variable
}

What is call by value and call by reference?

call by value-> A copy of the value is passed to the function, so original value is not modified. 
call by reference-> An address of value of passed to the function, so original value is modified.

Example:

void main()
{
  fun(a,b);// call by value
  fun(&a,&b);// call by reference
}

What is  Pointer?

A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast.Read more


What is Null Pointer?

A pointer that doesn't refer to any address of a value but NULL is known as the NULL pointer.

Example:

int *p=NULL; // Null Pointer

What is a Dangling pointer?

If a pointer is pointing any memory location but after some time another pointer deletes the memory occupied by the first pointer while the first pointer still points to that memory location, the first pointer will be known as the dangling pointer.


What functions are used for dynamic memory allocation in C language?
  •  malloc()
  •  calloc()
  •  realloc()
  •  free()

What is the difference between malloc() and calloc()?

malloc(): The malloc() function allocates the single block of requested memory. It has garbage value initially.
calloc(): The calloc() function allocates multiple blocks of requested memory. It initially initializes all bytes to zero.


What is Structure?

A structure is a user-defined data type that allows storing multiple types of data in a single unit. It occupies the sum of the memory of all members.

What is Union?

A union is a user-defined data type that allows storing multiple types of data in a single unit. But it doesn't occupy the sum of the memory of all members. It occupies the memory of largest member only.

What are the storage classes in c?
  • Static
  • Extern
  • Auto
  • Register
Write a program to swap two numbers without using the third variable?

void main()
{
 int a=10;
 int b=20;
 a=a+b;
 b=a-b;
 a=a-b;
 printf("%d %d",a,b);
}

OUTPUT:

20 10


No comments:

Post a Comment