Menu Close

C interview questions

  • What is programming language?
    • Programming language is a pre-defined application.
    • Programming language is standalone software.
    • It is compatible to OS.
  • What is the need of Programming language?
    • Programming languages used to develop applications.
    • Applications are used to communicate.
    • Communication is the process of sharing information.
  • What standalone application?
    • Application which is compatible to Operating System.
    • Application runs on single machine where it has installed.
  • What is web application?
    • Application run from different machines at a time.
    • Application is independent to OS.
    • Application run from the server machine.
  • What is platform dependency?
    • C and C++ languages are Platform dependent languages.
    • Using C and C++, we can develop standalone applications.
    • C compiler converts the source code into specific OS understandable instructions. Hence the compiled code can run on same OS is called Platform dependency.
  • What is Platform in-dependency?
    • Compiler converts the source code into the binary code which is understandable by different operating systems.
    • Interpreter involves in Platform in-dependency.
  • What is variable?
    • Variable is the Identity of memory location.
    • Variables are used to store the information.
    • C language supports Local and Global variables.
  • What is function?
    • A block of instructions with an identity.
    • Function is used to perform a task with logic.
    • Function takes input(arguments), process and return result.
  • Why program execution starts with main() function?
    • Application is used in communication.
    • Communication is possible with functionality.
    • Hence every application program starts with a function.
    • A standard function given to start communication with C program is called main() function.
  • What is data type?
    • In the declaration of variable, we need to specify its type.
    • Data type describes the size of memory allocated to variable and what type of data is allowed to store into that memory.
  • What are primitive data types?
    • Primitive data types are pre-defined with fixed size.
    • Examples are int, char, float….
  • What is type casting?
    • Conversion of data from one type to another type is called Casting.
    • Type casting happens at runtime.
  • What is sizeof() operator?
    • A pre defined function also called Operator.
    • It is used to find the size of data type variable, expression, array….
  • What is the use of limits.h header file?
    • Pre-defined header-file providing constant variables.
    • These variables represent the limits (ranges) of each data type.
  • What is operator?
    • It is symbol.
    • It performs operation on operands.
    • Variables, Constants and Functions in Expression called OPERANDS.
  • What is ternary operator?
    • The operator performs operation of 3 operands.
    • It is also called Conditional operator.

Syntax : Condition ? Expression1 : Expression2

  • Differentiate Relational and Logical operators?
    • Relational operators return a boolean value by validating operands in expression.
    • Logical operators return a boolean value by validating more than one expression.
  • What are shift operators?
    • These are binary operators.
    • These operators are used to move the binary bits in the memory.
    • Operators are >> , <<
  • What are assignment and Compound assignment operators?
    • Assignment operator is used to assign value to variable.
    • Compound assignment operators are modifying the value of variable.
    • Operators are  += , -= , *= , >>= …
  • What is block?
    • A block of instructions need to define with a keyword.
    • Blocks cannot be called – no identity to call.
    • Blocks like if, if-else are used to define a logic in the function.
  • What is loop?
    • A block of instructions need to define with a keyword.
    • Loops cannot be called – no identity to call.
    • Loops like while, for and do-while are used to define a logic in the function.
  • When we use break, return and exit?
    • Break statement is used to break the loop or switch case.
    • Return statement is used to return the control from function.
    • Exit statement is used to terminate the program execution.
  • What is the use of continue?
    • Continue statement is used to skip a particular iteration in loop execution.
  • Explain goto in C?
    • goto is a keyword.
    • It is used to send the cursor from one place to another place in program using labels.
  • What is stack memory?
    • Functions and Blocks execute from stack memory.
    • The memory allocate to execute a function in Stack is called Frame.
    • Stack frame will be deleted once function execution completes.
  • What is function prototype?
    • Declaration of function by specifying arguments type and return type.
    • Without prototype we cannot define and use a function in C program.
  • What is function Definition and Call?
    • Definition is a block of instructions which contains logic to perform a task.
    • Function call is a single statement and it is used to access function logic.
  • What is recursion?
    • Function calling itself is called recursion.
    • Calling the function from the definition of same function.
  • What is array?
    • It is a derived data type.
    • It is used to store more than one element of same type.
    • Array stores the values like student marks, mobile numbers….
  • What is string?
    • One dimensional character array
    • Strings can be defined with double quotes.
    • Strings are used to store values like names, address….
  • What is pointer?
    • A derived data type.
    • Pointer variable stores the address of memory location.
    • Pointers are called indirection operators.
    • Pointers used to access the information of memory indirectly.
  • What is the size of pointer?
    • Pointer size is equals to the size of integer.
    • Memory locations size depends on the type of compiler.
    • 16 bit compiler contains 2^16 memory locations.
    • Pointer stores an address hence the size is 2 bytes.
  • How to access element in array using pointers?
    • Using the concept of pointer arithmetic.
    • For example if the array name is “arr” and index variable is “I”, we use *(arr+i) expression to access the elements of array.
  • What is pointer modify?
    • Increment/Decrement the value of pointer variable.
    • It is also called pointer arithmetic.
    • It is used to access the elements of array using pointers.
  • What is call by value?
    • Call by value is the concept of calling the function by passing values as parameters.
    • We collect these values into arguments (local variables) of function.
  • What is call by reference?
    • Passing references of variables while calling the function.
    • We collect these references into pointer type variables in called function.
  • What is dangling pointer?
    • A pointer variable that stores the address of another function local variables.
    • Dangling pointer variables are used to get the instant results after function execution.
  • What is structure?
    • Structure is a user defined data type.
    • Structure is used to store more than one element of different data types.
    • Structures are used to store student, employee and account records data.
  • What is the size of structure?
    • Structure is a collection of elements of different data type
    • Size of structure is equals to the sum of sizes of individual elements.
    • Sizeof() operator can be used to find the size of structure type also.
  • What is union?
    • Unions were used in early days when memory at premium.
    • Union is a user defined data type.
    • Unions allowed to define more than one element but stores only one element at a time.
  • What is the size of union?
    • Size of union is equal to the size of element in that union occupies higher memory.
  • What is static memory?
    • Static memory represents fixed memory allocated to variables.
    • Primitive data type’s size is static.
    • C allows allocating both static and dynamic memory.
  • What is dynamic memory?
    • The concept of modifying the size of memory block at runtime depends on the data.
  • How can we allocate memory dynamically?
    • Stdlib.h header files providing pre-defined functionality to allocate memory dynamically in C language.
  • Explain malloc() function
    • Predefined function belongs to stdlib.h
    • It is used to allocate the memory dynamically to structures using pointers.
    • Malloc() function takes size as an input.
    • Malloc() function returns void* type after allocating the memory.
    • If the memory is not available, returns NULL pointer.
  • What are calloc() and realloc() functions?
    • Pre-defined functions belongs to stdlib.h
    • Calloc() allocate memory dynamically to arrays.
    • Calloc() allocate fixed size initially.
    • Realloc() function is used to increase or decrease the size of array allocated by calloc().
  • What is the use of free() function?
    • Function belongs to stdlib.h
    • It is used to release the memory which is allocated by calloc() or malloc().
    • Free() function intimates the executor about the memory which in not in use with specific pointer so that can be allocated to other variable.
  • What is typedef?
    • It is a keyword.
    • It is user defined data type.
    • It is used to create synonyms to existing data types.
    • These synonyms do not occupy memory and these are not permanent data types.
  • What is enum?
    • It is a keyword.
    • It is a user defined data type.
    • It is used to create set of elements assigned with constant integer values.
    • We can perform set operations using enumeration.
  • Explain the use of storage classes?
    • In the declaration of variable we need to specify storage class along with data type.
    • Storage class representation is optional.
    • C storage classes are auto, static, register and extern.
    • Storage classes provide information about storage location, default value, scope and availability of variable.