frequently asked questions in c

24
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

Upload: davidjlivi

Post on 10-Dec-2014

242 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Frequently asked questions in c

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

Page 2: Frequently asked questions in c

1. List out the various arithmetic operators in C?

+ Addition

- Subtraction

* Multiplication

/ Divison

% Modulo Division

Page 3: Frequently asked questions in c

2. What is an arithmetic expression?An arithmetic expression is a combination arithmetic

operators and operands of type integer.

Page 4: Frequently asked questions in c

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

Page 5: Frequently asked questions in c

4) Write the various logical operators in C?

&& - Logical AND

|| - Logical OR

! - Logical NOT

Page 6: Frequently asked questions in c

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

Page 7: Frequently asked questions in c

Example for Ternary Operator

Example:

A=10

B= 15

Max =(A>B )? A : B

Page 8: Frequently asked questions in c

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.

Page 9: Frequently asked questions in c

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

Page 10: Frequently asked questions in c

8) Write the program logic to find biggest among three without using ” , =”

return (a>b) ? (a>c ? a:c) : (b>c ? b: c)

Page 11: Frequently asked questions in c

9) What are the various looping statements available in C?a) While statement

b) Do..while statement

c) For statement

Page 12: Frequently asked questions in c

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.

Page 13: Frequently asked questions in c

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.

Page 14: Frequently asked questions in c

12) What is the starting index of an array in ‘C’?

The starting index of an array in ‘C’ is 0.

Page 15: Frequently asked questions in c

13) What are the types of array?One dimensional arrayTwo dimensional arrayMultidimensional array.

Page 16: Frequently asked questions in c

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.

Page 17: Frequently asked questions in c

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

Page 18: Frequently asked questions in c

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.

Page 19: Frequently asked questions in c

17) Write the syntax of the function definition.

return-value-type function-name( parameter-list ){

declarations and statements}

Page 20: Frequently asked questions in c

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

Page 21: Frequently asked questions in c

18) What is a recursive function?

A function that calls itself is called a recursive

function.

Page 22: Frequently asked questions in c

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

Page 23: Frequently asked questions in c

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

Page 24: Frequently asked questions in c

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.