C viva questions
C viva questions
What is a compiler?
Compile is a software program that transfer program developed in high level language intoexecutable
object code
What is IDE?
What is a program?
What is an algorithm?
The approach or method that is used to solve the problem is known as algorithm.
The smallest individual units are known as C tokens. C has six types of tokens Keywords,Constants,
Identifiers, Strings, Operators and Special symbols.
What is a Keyword?
Keywords are building blocks for program statements and have fixed meanings and thesemeanings
cannot be changed.
What is an Identifier?
Constants are fixed values that do not change during the program execution. Types
of constants are Numeric Constants (Integer and Real) and Character Constants (SingleCharacter,
String Constants).
What are the Back Slash character constants or Escape sequence charactersavailable in C?
Back Slash character constant are \t, \n, \0
What is a variable?
Variables are user-defined names given to memory locations and are used to store values. Avariable
may have different values at different times during program execution
Primary or Fundamental Data types (int, float, char), Derived Data types(arrays, pointers)and User-
Defined data types(structures, unions, enum)
While declaring a variable assigning value is known as initialization. Variable can beinitialized by using
assignment operator (=).
A variable which stores integer constants are called integer variable. A variable which storesreal
values are called floating-point variable. A variable which stores character constants arecalled
character variables.
C consist Arithmetic Operators (+, -, *, /,%), Relational Operators (<, <=, >, >=, !=), LogicalOperators
(&&, ||, !), Assignment Operators (=, +=, -=, *=, /=), Increment and DecrementOperators (++, --),
Conditional Operator(?:), Bitwise Operators(<<, >>, ~, &, |, ^) andSpecial Operators (. , ->, &, *,
sizeof)
What is Compiler?
Compiler is a program that converts human readable code (source code) into machine readable
code, this process is called compilation.
What is Interpreter?
Interpreter converts human readable code (source code) into intermediate code and then this
intermediate code is executed line by line.
What is Assembler?
Assembler is a program that converts assembly level language (low level language) into machine
level language.
What is Protocol?
What is IDE in C?
IDE is nothing but integrated development environment. IDE is a tool that provides user to create,
compile and execute C program. For example: Turbo C++, DevC++. These provide integrated
development environment.
What are Instructions?
In C instructions are the statements which tells computer to perform the specific task.
Text file contain data that can be easily understood by human. It includes letters, numbers and other
characters. On the other hand, binary files contain 1s and 0s that only computers can interpret.
What is Algorithm?
An algorithm refers to the step by step instructions written to solve any problem.
What is Flowchart?
What is a Program?
Compilation process translates source code into binary language. This binary language code is known
as object code.
This code contains object code and definition of predefined function from library. This code is written
in binary language.
Void is an empty data type that has no value. We use void data type in functions when we don’t want
to return any value to the calling functions.
Header files contain declaration of predefined functions. We can use any number of header files in
our program as per the requirement of predefined functions. Some header files are: stdio.h, conio.h,
math.h, stdlib.h, string.h, graphics.h
Explain the use of comma operator (,).
The printf() function is used to print the integer, character, float and string values on to the screen or
console. It is a predefined function.
The scanf() function is used to take input from the user or read some values from screen (or console).
It is a predefined function.
What is Console?
Console is known as output screen through which user interacts with the source code.
What is #include?
printf(): The printf() function is used to print the integer, character, float and string values on to the
screen.
scanf(): The scanf() function is used to take input from the user.
A variable which is declared as static is known as a static variable. The static variable retains
its value between multiple function calls.
Static variables are used because the scope of the static variable is available in the entire
program. So, we can access a static variable anywhere in the program.
The static variable is initially initialized to zero. If we update the value of a variable, then the
updated value is assigned.
Following are the differences between a call by value and call by reference are:
Description When a copy of the value is passed to the When a copy of the value is passed to the
function, then the original value is not function, then the original value is
modified. modified.
Memory Actual arguments and formal arguments Actual arguments and formal arguments
location are created in separate memory locations. are created in the same memory location.
In this case, actual arguments remain safe In this case, actual arguments are not
Safety
as they cannot be modified. reliable, as they are modified.
What is recursion in C?
When a function calls itself, and this process is known as recursion. The function that calls itself is
known as a recursive function.
What is an array in C?
An Array is a group of similar types of elements. It has a contiguous memory location. It makes the
code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed
after its declaration.
One-dimensional array: One-dimensional array is an array that stores the elements one after
the another.
Syntax:
1. data_type array_name[size];
Multidimensional array: Multidimensional array is an array that contains more than one
array.
Syntax:
1. data_type array_name[size];
What is a pointer in C?
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes
the performance fast. Whenever a variable is declared inside a program, then the system allocates
some memory to a variable. The memory contains some address number. The variables that hold this
address number is known as the pointer variable.
For example:
1. Data_type *p;
The above syntax tells that p is a pointer variable that holds the address number of a given data type
value.
A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far
pointer. A far pointer is a 32-bit pointer that obtains information outside the memory in a given
section.
If a pointer is pointing any memory location, but meanwhile another pointer deletes the
memory occupied by the first pointer while the first pointer still points to that memory
location, the first pointer will be known as a dangling pointer. This problem is known as a
dangling pointer problem.
Dangling pointer arises when an object is deleted without modifying the value of the pointer.
The pointer points to the deallocated memory.
In case of dynamic memory allocation, memory is allocated at runtime and memory can be
increased while executing the program. It is used in the linked list.
The malloc() or calloc() function is required to allocate the memory at the runtime.
1. For example
1. malloc()
o The malloc() function is used to allocate the memory during the execution of the
program.
o It does not initialize the memory but carries the garbage value.
o It returns a null pointer if it could not be able to allocate the requested space.
Syntax
2. calloc()
o The calloc() is same as malloc() function, but the difference only is that it initializes
the memory with zero value.
Syntax
3. realloc()
o The realloc() function is used to reallocate the memory to the new size.
o If sufficient space is not available in the memory, then the new block is allocated to
accommodate the existing data.
Syntax
1. ptr = realloc(ptr, newsize); // updating the memory size using realloc() function.
4. free():The free() function releases the memory allocated by either calloc() or malloc()
function.
Syntax
The above syntax releases the memory from a pointer variable ptr.
calloc() malloc()
The malloc() function allocates a single The calloc() function allocates multiple
Description
block of requested memory. blocks of requested memory.
It initializes the content of the memory It does not initialize the content of
Initialization
to zero. memory, so it carries the garbage value.
Number of
It consists of two arguments. It consists of only one argument.
arguments
The structure is a user-defined data type that allows storing multiple types of data in a single
unit. It occupies the sum of the memory of all members.
Structure variables accessing the same structure but the memory allocated for each variable
will be different.
What is a union?
The union is a user-defined data type that allows storing multiple types of data in a single
unit. However, it doesn’t occupy the sum of the memory of all members. It holds the
memory of the largest member only.
In union, we can access only one variable at a time as it allocates one common space for all
the members of a union.
In C, every local variable of a function is known as an automatic (auto) variable. Variables which are
declared inside the function block are known as a local variable. The local variables are also known
as an auto variable. It is optional to use an auto keyword before the data type of a variable. If no
value is stored in the local variable, then it consists of a garbage value.
But, if we use #define, we can compile and run a C program without using the main() function. For
example:
What is a token?
The Token is an identifier. It can be constant, keyword, string literal, etc. A token is the smallest
individual unit in a program. C has the following tokens:
2. Keywords: Keywords are the predefined words that are explained by the compiler.
3. Constants: Constants are the fixed values that cannot be changed during the execution of a
program.
5. Special characters: All the characters except alphabets and digits are treated as special
characters.
The argument passed to the main() function while executing the program is known as command line
argument. For example:
The ANSI stands for ” American National Standard Institute.” It is an organization that maintains the
broad range of disciplines including photographic film, computer languages, data encoding,
mechanical parts, safety and more.
The getch() function reads a single character from the keyboard. It doesn’t use any buffer, so
entered data will not be displayed on the output screen.
The getche() function reads a single character from the keyword, but data is displayed on the output
screen. Press Alt+f5 to see the entered character.
The new line escape sequence is represented by “\n”. It inserts a new line on the output screen.
What is typecasting?
The typecasting is a process of converting one data type into another is known as typecasting. If we
want to store the floating type value to an int type, then we will convert the data type into another
data type explicitly.
Syntax
1. (type_name) expression;
Yes, by holding the base address of array into a pointer, we can access the array using a pointer.
A loop running continuously for an indefinite number of times is called the infinite loop.
for(;;){
//code to be executed
while(1){
//code to be executed
do{
//code to be executed
}while(1);
#include<stdio.h>
void main(){
if(printf(“hello world”)){} // It prints the ?hello world? on the screen.
Ans. Storage classes represent the storage of any variable. There are four storage classes in C:
Auto
Register
Extern
Static
Ans. This is one of the commonly asked C programming interview questions. The data type specifies
the type of data used in programming. C language has some predefined data types with different
storage capacities:
Built-in data types: It includes int, char, double, float and void
Ans. The scope and lifetime of any variable are defined as the section of the code in which the
variable is executable or visible. Variables that are described in the block are only accessible in the
block. The variable’s lifetime defines the variable’s existence before it is destroyed.
Ans. Header files are those which contain C function declaration and macro definitions that are to be
shared between sourced files. Header files are generated with the extension .h.
Ans. A nested structure is used to make the complicated code easy. If we want to add the address of
employees with other more details, then we have to create a nested structure for it.
Ans. It enables you to declare a variable without bringing it into existence. The value is assigned to it
in a different block, and it can be changed in the various blocks as well. So extern storage specifier is
a global variable that can be used anywhere in the code.
Syntax:
(pointer_name)->(variable_name)
What is typecasting in C?
Ans. It is a way to convert constant from one type to another type. If there is a value of float data
type then you can typecast it into other data types.
Implicit conversion
Explicit conversion
while(0) means that the looping conditions will always be false and the code inside the while loop
will not be executed. On the other hand, while(1) is an infinite loop. It runs continuously until it
comes across a break statement mentioned explicitly.
What is the difference between actual parameters and formal parameters?
Ans. The differences between actual parameters and formal parameters are:
They are included at the time of function call. They are included at the time of the definition of the function.
What is a string?