C-Language interview questions and answers

VIVA QUESTION & ANSWERS

1) How many types of comments are there?

2 types of comments:Line comment (//) and block comment (/* --- */).

2) What is #?


 It is a preprocessed directive.ie: already processed or checked.

3) About stdio?


 It is standard input output header file.Functions are printf() for printing and

 scanf() for reading.Extension is (.h)

4) About conio?


 It is console input output header file.Functions are clrscr() for clear screen  getch() for get character(control from code screen to output screen and vice  versa).

5) How many keywords are there in c? What are they?

 32 keywords.

6) How many types of operators are there in c? What are they?

Arithmetic Operators

Increment and Decrement Operators

Assignment Operators

Relational Operators

Logical Operators

Conditional Operators

Bitwise Operators

Special Operators

7) What are the different type of decision-making statements?

  if
  if-else
  nested if-else
  else-if ladder
  switch statement

    8) Syntax for if statement

     if(expression)                     
       statement1;   
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
Syntax:switch (expression)
{
   case constant1:  codes to be executed if expression equals to constant1;
                             break;
   case constant2: codes to be executed if expression equals to constant3;
                            break; . . .
  default:             codes to be executed if expression doesn't match to any cases;
}
9) Syntax for if-else statement.   

(1 out of  2 will be executed).
if (expression)                      
{                             
 Block of statements;                      
}                    
 else                     
{                              
 Block of statements;                     
}

10) Syntax for nested if-else statement.

         
      if(condition 1) 
(outside block)     
 {    //beginning of (condition 1 block) 

11) Syntax for else-if ladder.

if(conditional-expression1)
{          
statement-block-1
}     
else if(conditional-expression2)
{
statement-block-2 ;
}
else if(conditional-expression3)
{
statement-block-3 ;
}
else
{
statement-block-4 ;
}
             
12) How many types of loops are there? What are they?

Loops are nothing but repetition. There are 3 types of loops.They are:

for syntax:

            for(initialization;condition;increment/decrement)
            {
                    statements;
            }
while syntax:

          while(test-expression)
               {
                      statements;
                 }
 do-while syntax:

                        do
                       {
                             statements;
                       }
                       while(test-expression);

13) Difference between while and do-while loop?

  In while,first condition is checked and then statements are executed.whereas in do-while, first statements are executed and then condition is checked.

14) Difference between main(),void main(),int main()


  main() is a function from where exactly  the execution starts and it is

          without a return type. Hence, return; at the end of the program.
          void main() – is a function where it doesn’t return anything to the operating 
          system. void is a keyword.
          int main() – it is a function where it returns 0 to the operating system.Hence,
          return 0; at the end of the program.

15) What is an Array?

 Array is a name given to contiguous memory location which consists of similar
        (homogeneous) data elements.

16) What is the difference between normal variable and array variable?


 Let us take an example:


         int a=4;
         a=5;
         printf(“%d”,a);

Here, ‘a’ value is printed as 5, because 4 is replaced with 5 and the value 4 is lost.
In order to avoid this disadvantage, we are using arrays where the editing of data individually can be done without disturbing the other elements in the array.

17) Array declaration and initialisation?

Array index starts from 0. Array variable consists of subscript. For example,
         int a[5]; // array declaration.

               0        1         2            3              4
      a    10        20         30           40              50


a[5]= { 10,20,30,40,50};  //this is called array initialization.
a[0]=10 , a[1]=20 , a[2]=30 , a[3]=40 , a[4]=50.
This is an integer array.

18) What is a function?


 A function is a set of operations to do a specific task.



19) How many types of functions are there?

 There are 2 types of functions.They are :
         a) user defined functions and
         b) pre-defined or builtin or library functions.

20) Examples of library functions.

 printf(),scanf(), etc.


21) What are the essentials when a function is written?


 1) Function prototype or declaration:

             It is a global declaration and written before main().
  2) Function call: It is written inside main().
  3) Function definition: It is written outside main().
            
22) What is the difference between actual arguments and formal arguments?

  The arguments inside main() are actual and outside main() are called formal arguments.

 For  Example:

        int add(int , int);  // function prototype
        int main()
        {
                add(a , b); //function call with actual arguments a,b
         }
         int add(int x,int y)  // function definition with formal arguments x,y
         {
                 //statements;
          }

23) What are string functions?

To include strings use header file called <string.h> Some of the functions are:

24) What is the difference between char and string?


 char is written in single quotes ‘ ‘.example:’a’ and string is written in double quotes” “.ex: “anurag”

25) Difference between gets() and puts() .

 gets() is from standard input to memory puts() is from memory to standard input

26) What is the format specifier for char and string?

char is %c and string is %s.
                   


Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

No comments:

Post a Comment