C Interview Questions and Answers

What is dynamic memory allocation?

Allocation of memory at the time of execution is called dynamic memory allocation. In C, It is done via using the standard library functions malloc() and calloc().

What functions are used for dynamic memory allocation in C language?

C provides four dynamic memory allocation functions, those are
malloc(), calloc(), realloc() and free()

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

malloc(): The malloc() function takes only one argument and used toallocates single block of requested memory. It has garbage value initially.
calloc(): The calloc() function takes two arguments and used toallocates multiple block of requested memory. It initially initializes all bytes to zero.

Explain realloc()?

The realloc() function can change the size of a memory space allocated by the malloc() ,calloc() and realloc() itself.

The syntax for the realloc() function is
void *realloc(void *block, size_t size);
Here block is the pointer to the start of a piece of memory space previously allocated.
size specifies the total byte number you want to change to.

What free() function do?

The free() function can be release unused allocated memory by the malloc(), calloc(), or realloc() function.

What are enumerated or enum types?

The enumerated data type can be used to declare named integerconstants.Enumerators are defined with the keyword enum.
By default, the first enumname starts with the value of 0 and the value of each name in the
rest of the list increases by one from left to right.

enum days{SUN,MON,TUE,WED,THU,FRI,SAT};

where SUN represent 0 and MON to SAT respectively 1 to 6

we can also assign any integer values to enum names.

What Is a Structure?

Structure is a user-defined data type and collection of heterogeneous data items,that is collection of different variables with their data type.
The data items in a structure are called members of the structure,whereasvthe structure member can be refer via dot operator (.) with structure variable and arrow operator (->) with structure pointer variable.
for ex
structure student as:

struct student {
introll_number;
charname[30];
inttotal_marks;
} student1;

What Is a Union?

union is similar to a structure, except that the data items saved in the union are overlaid in order to share the same memory location. That is, they all share the same starting address.
The allocated size of a union is at least as large as the size of the largest data item in the list of the union members in memory.

Like a structure, you can reference a union’s members by using dot and arrow operator with it variable.

What are the differences between a union and a structure?

The major differences between structure and union are:

(i) In structure every member has its own memory whereas in union its members share the same member space.
(ii) In structure, it is possible to initialize all the members at the same time which is not possible in case of union. 

What is command line arguments?

The arguments that we pass to main() at command prompt are called command line arguments. These arguments are supplied at the time of invoking the program.
The main()function can take arguments as:main(int argc,char *argv[]) { }
The first argument argc is known as argument counter. It represents the number of arguments in the command line.The second argument argv is known as argument vector. It is an array of char type pointers that points to the command line arguments.Sizeof this array will be equal to the value of argc.

What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

What is the difference between pre increment and post increment operator?

Post-increment (ex: x++) returns a copy of the original value before increment itself. Pre-increment (ex: ++x) returns a copy of the original value plus 1.
Ex:
int i=0, j, k;
j=i++;
k=++i;
printf("%d %d %d ", i, j, k);

Output :> 2 0 2    

Latest Updates

Trigonometry

What is the value of cot 4π/3 ?

Indian Politics

Article-24 of the Indian Constitution ‘Prohibition of employment of children in factories, etc’ deals with?

Article-134A of the Indian Constitution ‘Certificate for appeal to the Supreme Court’ deals with?

Chemistry

Who invented Aspirin?

Physics

A larger force on a rotating body results in larger?

What is the unit of the physical quantity, magnetic flux density?

Algebra

The system of equations 2x + 4y = 6 and 4x + 8y = 8 is ?

Time and Distance

A thief is spotted by a policeman from a distacne of 100 m. When the policeman starts the chase, the thief also starts running. If the speed of the theif is 8 km / hour and that of the policeman is 10 km/hour, then how far will the theif have to run before he is overtaken?

Algebra

Aman and Alok attempted to solve a quadratic equation. Aman made a mistake in writing down the constant term and ended up in roots (4, 3). Alok made a mistake in writing down the coefficient of x to get roots (3, 2). The correct roots of the equation are?

Compound Interest

The effective annual rate of interest corresponding to a nominal rate of 22% per annum payable half-yearly is?

Volume and Surface Area

If the volume of a cylinder is 2156 cubic cm and height is 14 cm, find its radius?

Algebra

What is the equation of the line which passes through the points (2, 3) and (- 4, 1)?

Triangles

In △ABC, the angle bisector of ∠A cuts BC at E. Find length of AC, if lengths of AB, BE and EC are 9 cm, 3.6 cm and 2.4 cm?

In a triangle, the length of the opposite side of the angle which measures 45° is 8√2 cm, what is the length of the side opposite to the angle which measures 90°?

General Knowledge of India

The boundary line between India and Pakistan is called?

Which city is located on the banks of the river Mahanadi?

Indian History

When was the battle of Haldighati fought?

In 1498, which Portuguese explorer discovered a new sea route from Europe to India?

General Knowledge of India

Chapchar Kut is a festival of which State?

Chemistry

In chemistry, soap is a salt of a ?

Indian Economy

Which of the following is a Direct tax?

Biology

Sauria lacertidae is the scientific name of?

Which of the following is a primary function of haemoglobin?

Average

A factory buys 8 machines.3 Machine A, 2 Machine B and rest Machine C. Prices of the machines are 100000, 80000 and 45000 respectively.Calculate the average cost of these machines?

Discount

Ticket for an adult is 500 and a child is 200. 1 child goes free with two adults. If a group has 20 adults and 8 children what will be the discount the group get?