0% found this document useful (0 votes)
3 views

C viva questions

The document provides a comprehensive overview of the C programming language, covering its history, structure, data types, and key concepts such as variables, operators, and memory management. It explains essential components like compilers, IDEs, algorithms, and functions, as well as specific features like pointers, arrays, and dynamic memory allocation. Additionally, it discusses various programming constructs, including recursion, structures, unions, and storage classes, along with practical examples and syntax.

Uploaded by

Lavanya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C viva questions

The document provides a comprehensive overview of the C programming language, covering its history, structure, data types, and key concepts such as variables, operators, and memory management. It explains essential components like compilers, IDEs, algorithms, and functions, as well as specific features like pointers, arrays, and dynamic memory allocation. Additionally, it discusses various programming constructs, including recursion, structures, unions, and storage classes, along with practical examples and syntax.

Uploaded by

Lavanya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

C viva questions

Who developed C language?

C language was developed by Dennis Ritchie in 1970 at Bell Laboratories.

Which type of language is C?

C is a high – level language and general purpose structured programming language.

What is a compiler?

Compile is a software program that transfer program developed in high level language intoexecutable
object code

What is IDE?

The process of editing, compiling, running and debugging is managed by a single


integratedapplication known as Integrated Development Environment (IDE)

What is a program?

A computer program is a collection of the instructions necessary to solve a specific problem.

What is an algorithm?

The approach or method that is used to solve the problem is known as algorithm.

What is structure of C program?

A C program contains Documentation section, Link section, Definition section, Globaldeclaration


section, Main function and other user defined functions

What is a C token and types of C tokens?

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.

How many Keywords (reserve words) are in C?

There are 32 Keywords in C language.

What is an Identifier?

Identifiers are user-defined names given to variables, functions and arrays.

What is a Constant and types of constants in C?

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

What are the Data Types present in C?

Primary or Fundamental Data types (int, float, char), Derived Data types(arrays, pointers)and User-
Defined data types(structures, unions, enum)

How to declare a variable?

The syntax for declaring variable isdata type variable_name-1, variable_name-2,....variable_name-n;

What is meant by initialization and how we initialize a variable?

While declaring a variable assigning value is known as initialization. Variable can beinitialized by using
assignment operator (=).

What are integer variable, floating-point variable and character variable?

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.

How many types of operator or there in C?

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?

Protocol is nothing but a set of rules to be followed by a programmer.

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.

C language has been developed in which language?

C language has been developed using assembly language.

What is the difference between Text Files and Binary Files?

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.

Is C a Structured Programming Language?

Yes, C language is structured language.

C is successor of which programming language?

What is Algorithm?

An algorithm refers to the step by step instructions written to solve any problem.

What is Flowchart?

A flowchart is a diagrammatic or symbolic representation of an algorithm. It uses various symbols to


represent the operations to be performed.

What are Library Functions?

Library functions are predefined functions and stored in .lib files.

What is a Program?

A computer program is a collection of the instructions necessary to solve a specific problem.

What is Object Code?

Compilation process translates source code into binary language. This binary language code is known
as object code.

What is Executable Code?

This code contains object code and definition of predefined function from library. This code is written
in binary language.

What is void in C 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.

What is the meaning of Header File? Name some Header Files.

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 (,).

Comma operator can be used to separate two or more expression.

What is the use of printf() function?

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.

What is the use of scanf() 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?

It is a pre-processor directive. It is used to include any header file in our program.

What is the use of printf() and scanf() functions?

printf(): The printf() function is used to print the integer, character, float and string values on to the
screen.

Following are the format specifier:

 %d: It is a format specifier used to print an integer value.

 %s: It is a format specifier used to print a string.

 %c: It is a format specifier used to display a character value.

 %f: It is a format specifier used to display a floating point value.

scanf(): The scanf() function is used to take input from the user.

What is the use of a static variable in C?

Following are the uses of a static variable:

 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.

What is the difference between call by value and call by reference in C?

Following are the differences between a call by value and call by reference are:

Call by value Call by reference

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.

The addresses of actual arguments are


The copies of the actual arguments are
Arguments passed to their respective formal
passed to the formal arguments.
arguments.

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.

Arrays are of two types:

 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.

What is a NULL pointer in C?


A pointer that doesn’t refer to any address of value but NULL is known as a NULL pointer. When we
assign a ‘0’ value to a pointer of any type, then it becomes a Null pointer.

What is a far pointer in C?

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.

What is dangling pointer in C?

 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.

What is dynamic memory allocation?

 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.

 An allocation or deallocation of memory is done at the execution time of a program.

 No dynamic pointers are required to access the memory.

 The dynamic memory is implemented using data segments.

 Less memory space is required to store the variable.

1. For example

2. int *p= malloc(sizeof(int)*10);

The above example allocates the memory at runtime.

What functions are used for dynamic memory allocation in C language?

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

1. ptr = (cast-type*) malloc(byte-size) // allocating the memory using malloc() function.

2. calloc()
o The calloc() is same as malloc() function, but the difference only is that it initializes
the memory with zero value.

Syntax

1. ptr = (cast-type*)calloc(n, element-size);// allocating the memory using calloc() func


tion.

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.

In the above syntax, ptr is allocated to a new size.

4. free():The free() function releases the memory allocated by either calloc() or malloc()
function.

Syntax

1. free(ptr); // memory is released using free() function.

The above syntax releases the memory from a pointer variable ptr.

What is the difference between malloc() and calloc()?

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

It returns a pointer pointing to the It returns a pointer pointing to the


Return value
allocated memory. allocated memory.

What is the structure?

 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.

 The structure members can be accessed only through structure variables.

 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.

What is an auto keyword in C?

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.

Can we compile a program without main() function?

Yes, we can compile, but it can’t be executed.

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:

1. Identifiers: Identifiers refer to the name of the variables.

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.

4. Operators: An operator is a symbol that performs the particular operation.

5. Special characters: All the characters except alphabets and digits are treated as special
characters.

What is command line argument?

The argument passed to the main() function while executing the program is known as command line
argument. For example:

What is the acronym for ANSI?

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.

What is the difference between getch() and getche()?

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.

What is the newline escape sequence?

The new line escape sequence is represented by “\n”. It inserts a new line on the output screen.

What is the maximum length of an identifier?

It is 32 characters ideally but implementation specific.

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;

Can we access the array using a pointer in C language?

Yes, by holding the base address of array into a pointer, we can access the array using a pointer.

What is an infinite loop?

A loop running continuously for an indefinite number of times is called the infinite loop.

Infinite For Loop:

for(;;){

//code to be executed

Infinite While Loop:

while(1){

//code to be executed

Infinite Do-While Loop:

do{

//code to be executed

}while(1);

Write a program to print “hello world” without using a semicolon?

#include<stdio.h>

void main(){
if(printf(“hello world”)){} // It prints the ?hello world? on the screen.

Name some different storage class specifiers in C?

Ans. Storage classes represent the storage of any variable. There are four storage classes in C:

 Auto

 Register

 Extern

 Static

What are the data types supported in the C Programming language?

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

 Derived data types: It includes array, pointers, and references

 User-defined data types: Union, structure, and Enumeration

What do you mean by the scope and lifetime of a variable in C?

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.

What are header files in C?

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.

There are two types of header files:

 Programmer generated a header file

 Files that come with your compiler

Syntax: #include <file>

What is the use of nested structure in C?

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.

What is the use of an extern storage specifier?

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.

When is the arrow operator used?


Ans. The Arrow operator is used to access elements in structure and union. It is used with a pointer
variable. Arrow operator is formed by using a minus sign followed by a greater than a symbol.

Syntax:

(pointer_name)->(variable_name)

Name the keyword used to perform unconditional branching.

Ans. A go-to statement is used to perform unconditional branching.

What is the use of the comma operator?

Ans. It is used to separate two or more expressions.

E.g. printf (“hello”);

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.

There are two types of typecasting in C:

 Implicit conversion

 Explicit conversion

What do you understand by while(0) and while(1)?


Ans. In while(1) and while(0), 1 means TRUE or ON and 0 means FALSE or OFF.

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:

Actual Parameters Formal Parameters

They are included at the time of function call. They are included at the time of the definition of the function.

Actual Parameters do not require data type but


the data type should match with the Data types need to be mentioned.
corresponding data type of formal parameters.

These can be variables, expressions, and constant


These are variables with their data type.
without data types.

What is a string?

String is a collection of characters which is terminated by a null character.

What are string handling functions?

You might also like