frequently asked questions in c
DESCRIPTION
TRANSCRIPT
Frequently Asked Questions in C!
Developed by David Livingsto J, Coimbatore Contact email: [email protected] Blogs maintained by the author includees:
futureforyou.net futureforyou.biz
1. List out the various arithmetic operators in C?
+ Addition
- Subtraction
* Multiplication
/ Divison
% Modulo Division
2. What is an arithmetic expression?An arithmetic expression is a combination arithmetic
operators and operands of type integer.
3) What are the various relational operators in C?
< Less than
> Greater than
= Equal
!= Not equal
>= Greater than or equal to
<= Lesser than or equal to
4) Write the various logical operators in C?
&& - Logical AND
|| - Logical OR
! - Logical NOT
5) Explain ternary operator in C.The ternary opearor is also known as Conditional
opearator. Syntax:(expr 1) ? (expr-2) : expr-3)
The expr-1 is evaluated first. If it is true, the expr-2 is
evaluated and it is the value of expr-1 . If expr-1 is
false, expr-3 is evaluated and it is the value for expr-
1
Example for Ternary Operator
Example:
A=10
B= 15
Max =(A>B )? A : B
6) What is the use of decision making statement?Decision making statement is used to break the normal
flow of the program and execute another part of the program based on some condition.
7) List the various decision making statements available in C ?1. If statement
2. If ..else statement.
3. Nested if statement
4. If ..else ladder statement
5. Switch statement
8) Write the program logic to find biggest among three without using ” , =”
return (a>b) ? (a>c ? a:c) : (b>c ? b: c)
9) What are the various looping statements available in C?a) While statement
b) Do..while statement
c) For statement
10) What is the difference between while and do..while statement?* While is an entry controlled statement. The
statements inside the while may not be executed at all when the condition becomes false at the first attempt itself.
* The do..while is an exit controlled statement. The
statements in the block are executed at least once.
11) What is an array?
* An array is a collection of data of same data type.
* The elements of the array are stored in consecutive
memory locations.
* The array elements can be accessed using an integer
called index.
12) What is the starting index of an array in ‘C’?
The starting index of an array in ‘C’ is 0.
13) What are the types of array?One dimensional arrayTwo dimensional arrayMultidimensional array.
14) What is a two dimensional array?Two dimensional array is an array of two dimension –
rows and columns. The elements in this array are referenced with the help of its row and column index.
15) What are the advantages of using functions in a C program? * Debugging is easier* It is easier to understand the logic involved in the
program* Testing is easier* Recursive call is possible* Irrelevant details from the user's point of view (i.e.,
the code) are hidden from the users of a function* Functions are helpful in generalizing the program
16) What is a function?
A function is a sub procedure that contains a set ofstatements for performing a task. Functions reduce the amount of work involved in reusing some code. They are normally called from the main part of the program (main()) for their execution.
17) Write the syntax of the function definition.
return-value-type function-name( parameter-list ){
declarations and statements}
Elements of a Function:
–Function-name: any valid identifier
–Return-value-type: data type of the result (default int). void – indicates that the function returns nothing
–Parameter-list: comma separated list, declares parameters. A type must be listed explicitly for each parameter unless, the parameter is of type int
18) What is a recursive function?
A function that calls itself is called a recursive
function.
19) What are the two methods of function call?
Call by value
* Copy of argument is passed to function* Changes in function do not reflect in actual
parameter* Can be used when function does not need to modify
argument* Helps us to avoid accidental changes in the actual
parameters
Method of Function Call
Call by reference* Passes the reference (address) of the actual
parameter to the formal parameter* Changes in function reflect in actual parameter* Can be used only with trusted functions
20) What is the use of return statement?The return statement is used to exit from the callee
(called function) and return a value to its caller.