Interview questions on c for freshers/beginners

C programming interview questions

What is c? Who invented the c language?

C is a procedure oriented computer programming language that features economy expression, modern control flow, data structure and having a rich set of operators.it is invented by Dennis Ritchie in 1972 at bell and bell lab.

Tell some features of c language?

  • It has an extensive variety of operators and data types that offers a vast range of options.
  • It is modular in nature.
  • C programs are portable and can run on any compiler without modification.
  • It is a dominant language as it provides a wide variety of data types and functions as well as control statements.
  • Efficient use of pointers.
  • It is very simple to write assembly language codes programs in c.

What are the software and hardware requirements of c language?

Hardware Requirements: – Pc with 512 kb base memory.

Software requirements:-c compiler.

Write a c program to print “hello world”?

#include<iostream.h> { printf(“hello world”); }

What are reserved words?

A reserved word is a type of c tokens also known as keywords.

Is there is any inbuilt input and output statement in c?

No, there is no inbuilt input/output statement in c.For input and output operations we use Printf and Scanf.

Why we use Scanf in c?

We use Scanf as a function to input data via the keyboard.

Which function is used in c for printing “captions”?

Printf is used to print captions in C.

Why is C known as a middle-level language?

C supports various features of both low-level and high-level programming languages, so, it is referred as middle-level language.

What is putchar()?

Putchar is a function used to read a single character from the keyboard.

What is getchar()?

Getchar is a function used for writing characters one at a time on the screen.
What are header files?

Header files provides definitions and declarations for library functions.E.g->math.h,conio.h etc.

Types of C compilers?

Turbo c, Microsoft c, Hisoft c, lattice c.

What are identifiers?

Variables, constants, and functions are known by a common name called identifiers.

What are tokens?

Smallest individual units used in c programs known as Tokens.

For e.g->If ,float,int,char,else,break,switch,continue etc.

How many types of c tokens are there in C?

There are six types of ‘c tokens’ are there :-

  • Keywords.
  • Identifiers.
  • constants.
  • strings.
  • special symbols.
  • Operators.

primitive data types in c?

fundamental data types in c are as:-

data type range
char -128 to 127
int -32768 to 32767
float 3.4E-38 to 3.4e+38
double 1.7E-308 to 1.7E+308

what are constatnts?

Identifiers whose value is fixed during the execution of program known as constants.

e.g->int constants,float constants etc.

What are variables?

Variables are those whose value changes during the execution of a program.

Types of variables?

Three types of variables:-

  • Automatic variable or internal variable.
  • External or global variable.
  • Static variable

If we do not include in our program then clrscr() will work or not?

No, for clrscr() and getch() to work conio.h header file is required.

What is an expression?

The expression is a sequence of operand and operators which specify the computation of values.

Types of operators used in c?

Operators used in c are as follows:-

  • Arithmetic operators- e.g. Addition(+),multiplication(*),subtraction(-),Division(/).
  • Relational operators- e.g. Less than(<), greater than(>),etc.
  • Logical operators- e.g. AND(&&),OR(||),NOT(!).
  • Assignment operators- e.g. Let a=2,b=3, then c=a+b=5.
  • Conditional operators- e.g. If else statements etc.
  • Bitwise opeator- e.g. and(&),or(|),exclusive or(^),etc.
  • Increment /decrement operatos- e.g. a++,a–,++a,–a.
  • Special operators- e.g. pointer, This pointer etc.

 

What is a while statement?

“While Statement” is an entry control loop statement, when the condition is evaluated, and the condition is true then the body of the loop gets executed.
syntax:-while(condition) { body loop; }
How can we perform jump out of the loop?

We can jump out of the loop by using break or goto statement.

Why we use continue statement?

It is used to skip the part of the body under certain condition.
Syntax-Continue;.

What is an array?

An array is a collection of same data type values stored into a single variable. Types of arrays are:-

  • 1-d array
  • 2-d array
  • Multidimensional array

what is a string?

A string is a collection of characters. There are a lot of types of string few names are as follows:-

  • strlen- It is used to find the actual length of the string.
  • srtcpy- It is used to copy the string.
  • strupr- it is used to convert the lower case alphabets to uppercase.
  • strlwr- it is used to convert uppercase alphabets to lowercase. etc.

What is a function?

A collection of some statements into a single logical unit known as “function.”

What is recursion?

When a function calls itself within a function known as recursive function and the process is known as recursion.

Types of storage classes?

  • Static
  • Register
  • Automatic
  • External

What is a header file?
header files are the collection of definitions and declarations of library functions. Fog e.g->limits.h,stdlib.h,math.h,signal.h etc.
types of c instructions?

  • Constant declaration.
  • Arithmetic instructions.
  • Control instructions.

list of I/o functions?

  • scanf
  • getchar
  • printf
  • getch
  • gets

define.break?

Break statement forces the loop to exit immediately.

define.continue?

Continue loop instead of terminating the loop will skip the rest of the code in a current block and will return to the evaluation part of the loop.

What is a nested loop?

A nested loop is a loop inside another loop.
For e.g->we use nested loop in the diamond program.
List five library names with the description?

  • Math.h———->contains math function used in c.
  • limits.h——–>define the boundaries of different types of data integers.
  • signal.h——–>conatins state functions.
  • stdio.h ——–>incorporate functions.
  • time.h ———>functions related to time and date.

write a hello program in clanguage?

#include

int main()

{

printf(“hello”);

}

what are global variables?

Global variables are those which can be accessed by any method and function within a program.

What are local variables?

Local variables are those which are accessible by only that functions or methods in which they are defined.

What is the Difference between errors and debug?

Error: – Ab error is a problem occurred during creation of a program.

Debug: – Debug is the process of fixing the errors or problems.

Define.pointer?

A pointer is a variable that holds the memory address and represents a location of data items such as variables.

define. This pointer?

This pointer is that pointer that holds the address of the current variable.

What is a friend function?
A friend function is a function that is not a member of a class but has access to the class’s private and protected members.
Types of errors in c?

There are following errors in c:-

  • compile time errors.
  • linker errors.
  • logical or virtual errors.
  • run time errors.
  • divide by 0.
  • value out of range

what are operators?
Operators are the symbols that operated on a particular data types.
How many types of operators are there in c?

Types of operators in c are as follows:-

  • Arithmetic
  • Relational
  • Logical
  • Assignment
  • Conditional
  • Bitwise

what are unions?

Union is a data type with two or more members similar to the structure but in the union all members share common memory location.

What are structs?

A struct or structure is a user-defined data type that handles data groups related logically.

define.DMA?

Dynamic memory allocation is the practice of assigning memory locations to variables during execution of the program by explicit request of the programmer.

Deine.malloc,calloc,realloc and free with their syntax?

Malloc: -Allocates memory to variable dynamically when requied.synatx->void malloc(size_tsize)

Calloc: -allocates storage to a variable while the program is running.syntax->void calloc(size_tz,size_tsize)

Realloc: -By using realloc we can change the size of the allocated area.syntax->void realloc(void*ptr,size_tsize).

Free: -To release the reserved area we will use free.syntax->void free(void*ptr).

Give some examples of symbolic constants?

Area of the circle=pi*radius square.
We cannot have the symbol of pi so we Use PI whose value is by default 3.14 replaced by the compiler when PI comes.

Give some examples of keywords?

IF, while, do, break, continue, etc.

How many types of statements used in c?

List of statements used in c are:-

  • If
  • switch
  • goto
  • while
  • do while
  • break
  • continue
  • If else etc.

Which symbol is used for making a statement comment?
// is used.
What is an operator precedence?
Operator precedence is used to perform complex calculations such that which operator will evaluate first.