Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

C Chapter 6

Q. Define the comments in C.

Ans:- Comments are the non-executable part of program. Comments are used to provide information about lines of code written by developer. It is widely used for documenting code. There are 2 types of comments in C language.

1. Single Line Comments - Represent By \\
2. Multi Line Comments - Start from /* and ends from */ use when we want to create more then one line as an comment. e.g. /*........*/

Q. Write about the Escape Sequences in C.

Ans:- An escape sequence in C language is a sequence of characters that doesn't represent itself. These are having a specific meaning. It is composed of two or more characters starting with backslash \. For example: \n represents new line.

List of Escape Sequences in C

Escape Sequence -  Meaning
\n     - New Line
\r - Carriage Return
\a - Alarm or Beep
\b - Backspace
\f - Form Feed
\t - Tab (Horizontal)
\v - Vertical Tab
\\ - Backslash
\' - Single Quote
\" - Double Quote
\? - Question Mark
\nnn - octal number
\xhh - hexadecimal number
\0 - Null

Q. What are the constants in C?

Ans:- A constant is a value or variable that can't be changed in the program. There are different types of constants in C programming.

List of Constants in C

Decimal Constant - 70, 20, 450 etc.
Real or Floating-point Constant - 11.3, 25.2, 450.6 etc.
Octal Constant   - 020, 030, 046 etc.
Hexadecimal Constant - 0x3b, 0x7b, 0xaa etc.
Character Constant  - 'z', 'b', 'x' etc.
String Constant - "Z", "c program", "ZKing Institute" etc.

There 2 ways to define constant in C

 1. const keyword - The const keyword is used to define constant in C programming. e.g. const int z=10;

2. #define preprocessor - The #define preprocessor is also used to define constant. e.g. #define m 10

Q. Define about the if-else statement in C Language.

Ans:- The if statement in C language is used to perform operation on the basis of condition or operators applied on to opernads(Variables). By using if-else statement, we can perform operation either condition is true or false.

Types of if-else statements

If statement
If-else statement
If else-if ladder
Nested if

If Statement

If statement in C language is used to execute the code if condition is true. Syntax is given below:

//code to be executed

If-else Statement

If-else statement in C language is used to execute the code if condition is true or false. Syntax is given below:

//code to be executed if condition is true
//code to be executed if condition is false

If else-if ladder Statement

If else-if statement is used to execute one code from multiple conditions. Syntax is given below:

//code to be executed if condition1 is true
else if(condition2)
//code to be executed if condition2 is true
else if(condition3)
//code to be executed if condition3 is true
//code to be executed if all the conditions are false

Nested if-else

In Nested if-else we can use the if-else statements also inside the if-else statements.

Q. Write about the switch case statement in c.

Ans:-  Switch statement in C language is used to execute the code from multiple conditions. But can't able to apply operator with case.

The syntax of switch statement is given below:

case value1:  
 //code to be executed;  
 break;  //optional
case value2:  
 //code to be executed;  
 break;  //optional
 code to be executed if all cases are not matched;  

Q. Which rules are followed in switch-case? and what is the fall through state?

Ans:- Rules are given below used in switch-case.

1. The switch expression must be of integer or character type.

2. The case value must be integer or character constant.

3. The case value can be used only inside the switch statement.

4) The break statement in switch case is optional it is not must. If there is no break statement found in switch case, all the cases will be executed after matching the case value. It is known as fall through state of C switch statement.

No comments:

Post a Comment