Explain different data types modifiers available in C.
Primary data type: C supports five fundamental data types such as integer (int), character (char), floating point (float), double and void.
Derive data type: This data type derive from primary data types such as arrays, functions, structures and pointers.
User-defined data type: C supports a feature known as "type defintion" that allows user to define an identifier.
Explain conditional operator with proper examples.
It checks the condition and executes the statement depending on the condition.
A conditional operator is ternary operator i.e. it works on 3 operands.
Conditional operator consist of 2 symbols: (i) Question mark (?) and (ii) Colon (:).
Syntax : condition ? exp1 : exp2;
It first evaluate the condition, if it is true (non zero) then "exp1"is evaluated, if the condition is false (zero) then "exp2" is evaluated.
printf("Enter your age:");
// ternary operator to find if a person can vote or not
(age >= 18) ? printf("You can vote") : printf("You cannot vote");
Distinguish between while and do while loop. Explain with an example.
While Do While
In while loop condition is checked first and then the statement is executed In do-while statement is executed at least once thereafter condition is checked
It follows top-down approach It follows bottom-up approach
For single statement, we do need to add brackets In do white brackets are always needed
While loop is entry controlled loop Do while is an exit controlled loop
Here “while” keyword is used Here “do while” keyword is used
If the condition is false initially, the loop body is never executed The loop body is executed at least once, regardless of the initial condition