C Interview Question-Part 2

Posted on:
tags: , , , , ,
 C Interview Question-Part1

1) What are Macros?
    Macros are preprocessor, it’s unique feature of C language. Preprocessor improves the readability of the program and hence the developed code is more efficient.
Preprocessor directives consist of three sub categories
•Macro substitution division
•Complier control division
•File inclusion division

2) What is the difference between char *a and char a[]?
    Char a[] = “Name”
    The above statement allocates 5 memory location, for the above declared statement.
    Char *a = “Name”
    in front of a shows pointer declaration. The complier asks to place to hold the pointer. Memory address will given the name ‘a’ and it points to the array of seven character.

3) What is the difference between malloc() and calloc()?
     The two functions mainly is to allocate memory and they are commonly called as memory managers.
     Malloc()  :- Malloc function take one argument
     Calloc()  :- Calloc function take two argument in a time. The bits in the allocated space are initialized to zero.

4) When should a type cast not be used?
    Program which uses const declaration should not override using type cast. This will cause the program not to run sucessfuly. Type cast cannot be used to turn pointer from one data type to another.

5) When is a switch statement better than multiple if statements?
    Switch statement is better used when it required to check more then one condition with the same variable. A switch statement check the condition only ones.

6) Define and explain scanf () function?         
   Scanf() function get the input from the user. It contains two argument.
   First argument: - specify the datatype
   For example: - %f This tells that the value will be in floating point
   Second argument: - name in which the data to be stored
   For example: -  &f1 the entered value is stored in f1.

7) Explain ‘variable scope’, ‘local scope’ and ‘global scope’ ?
    Any variable declared inside the function are said to be local variable.  These variable have meaning only within the function. Any variable declared outside the function are said to be global variable
    Scope of the variable: - the extent to which a variable is accessible is said to be scope of the variable.

8) What are signed variables?
    When a variable is initialized as integer, it can take positive or negative this is called as signed variables. Range of value that the variable can hold depend on the system.


9) What is operator precedence?
    Operator precedence, tells the order in which the c complier executes a expression. It uses the BODMAS rule                     
Brackets first
Orders (ie Powers and Square Roots, etc.)
Division and Multiplication (left-to-right)
Addition and Subtraction (left-to-right)

10) What is stack?
 Stack operates under the rule of last in, first out. It contains two basic operations Pop and push. A stack can hold any data type. Stack doesn’t perform flexible operation.

11) Explain about the functions strcat() ?
  Strcat() function is used to concatenate the strings. It appends a copy of the string in the source to the destination location
  For example:- strcat(str, “C”)
  Strcat(str, “programming”) 
  Output :- C programming

12) Explain strcmp()?
    Strcmp() function, compares to string character by character if any mismatch occurs then it will return the difference between the non matching value in ASCII code else if two strings compared till the end and they are same, then it return the value zero.

13) Difference between union and structure?
    Union and structure groups different variables together. UNION treats different variable with same memory space whereas structure uses different space for different variable.    

14) What is Register variable?
      Register variable are automatic variable. Register variable stores the data in the CPU. Storing and retrieval of data are quiet easy. Variables that are used repeatedly in the program can be stored as register variable for easy storage and retrieval. 

15) State some significant uses of arrays in C programming?
      Elements in a array are for char data type and can store single character in each element. The significant use of array is that the ability to store the strings as text.
16) What is heap?
      Heap allocates memory for malloc(), realloc and calloc. It is more flexible then stack.

17) What is memory leak?
      An allocated memory which is no longer needed but the memory space is not deallocated.
18) What are the basic data types in C?
      Four data types in C
         Int,float, char,double.

19) List any two format specifiers?
        %d can hold integer whole number.
        %c can hold single character value.

20) Define and explain about! Operator?
       It is a unary operator which is used before single operator. The not operator return the inverse value. It is used in programming which require to change the value of the variable.

21) What is static variable?
        Static variable are constant variable whose value remain the same throughout the program. Static variable are instant variable

22) How can you determine the size of an allocated portion of the memory?

        The malloc or free implementation would determine the size of the memory easily.

23) Why do we use structure?
      Structures are used for various purpose
          o Use of structure variable
          o To develop individual array.

24) Define these functions fopen(), fread(), fwrite() and fseek()?
      Fopen():- function to open a file, the pointer points to the first record in the file.
       Fread():- it reads the file were the pointer is pointing.
      Fseek():- This function enables to move from one record to another.
      Fwrite:- This function write data in the file were the pointer is pointing.

25) What are logical operators in C?
      Logical operators in C are AND and OR operator.
      AND denoted by && for example exp1&& exp2
      OR denoted by || for example exp1||exp2

 ---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 

                        

No comments:

Post a Comment

< >