C commonly asked interview questions

What you will learn here :

  • C commonly asked interview questions

1)What is difference between structure and union?

1)Structure and union both are similar in the data storage means both can store similar or different types of data but both are different in memory allocation.
2)In structure separate memory location is allotted to each member of the ‘structure’ where in union All members of the ‘union’ share the same memory location.
3)In structure, the Size of structure = sum of size of all the data members where in union, the size of union=size of the largest members.
4)The structure is created using keyword struct where the union is created using the keyword union.

2)what is difference between macro and function?

1)macro is used to define a constant where function is used avoid code redundancy.
2)In a macro call the preprocessor replaces the macro template with its macro expansion where in a function call the control is passed to a function along with certain arguments, some calculations are performed in the function and a useful value is returned back from the function.
3)macro runs faster as compared to function
4)macro increases the code size where function reduces the code size.

3)What is difference between array and structure?

1)Array is collection of similar data type where structure is collection of similar or different data type.
2)Array elements are accessed by using index where structure elements are accessed by using dot operator.
3)In array data store individually where in structure data store in name(key) and value pair.

4)How to access structure elements in c?

In the c structure element is accessed by using the dot operator.

5)Can function return multiple values in c?

Yes, it is possible. With return statement, function returns only one value at a time. By using a pointer in function, a function can return more than one value at a time.

6)What is difference between ternery operator and if else statement?

In ternery operator we can write only one statement but in case of if else statement we can write more than one statement

7)Who is faster between switch and if else statement?

the switch is faster than the if-else but the switch does not support float as case value, the switch can not have a duplicate value.

8)What is difference between macro and enum?

9)How to access variables of structure using pointer?

Variables of the structure using a pointer is accessed by using the Arrow operator (->).

10)is it manditory to mention size of array at the declaration?

No it is not manditory to mention size of array if you are declaring and initialize at the same time. But if you are declaring first and then initializing then declaring size of array is manditory.

You may also like...

Leave a Reply