0% found this document useful (0 votes)
139 views14 pages

CP Viva

c programing vivA questions

Uploaded by

neeraj patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views14 pages

CP Viva

c programing vivA questions

Uploaded by

neeraj patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

1.What is C language and Why is C called a mid-level programming language?

C is a mid-level and procedural programming language. The Procedural programming


language is also known as the structured programming language is a technique in which large
programs are broken down into smaller modules, and each module uses structured code. This
technique minimizes error and misinterpretation.

C is called a mid-level programming language because it binds the low level and high -level
programming language. We can use C language as a System programming to develop the
operating system as well as an Application programming to generate menu driven customer
driven billing system.

2.Who is the founder of C language?

Dennis Ritchie.

3. When was C language developed?

C language was developed in 1972 at bell laboratories of AT&T.

4.What are the features of the C language?

The main features of C language are given below:

 Simple: C is a simple language because it follows the structured approach, i.e., a


program is broken into parts
 Portable: C is highly portable means that once the program is written can be run on
any machine with little or no modifications.
 Mid Level: C is a mid-level programming language as it combines the low- level
language with the features of the high-level language.
 Structured: C is a structured language as the C program is broken into parts.
 Fast Speed: C language is very fast as it uses a powerful set of data types and
operators.
 Memory Management: C provides an inbuilt memory function that saves the memory
and improves the efficiency of our program.
 Extensible: C is an extensible language as it can adopt new features in the future.

5.What is Preprocessor?

Ans: A Preprocessor Directive is considered as a built-in predefined function or macro that


acts as a directive to the compiler and it gets executed before the actual C Program is
executed.

In case you are facing any challenges with these C Programming Interview Questions, please
write your problems in the comment section below.

6.Why is C called the Mother of all Languages?


Ans: C introduced many core concepts and data structures like arrays, lists, functions,
strings, etc. Many languages designed after C are designed on the basis of C Language.
Hence, it is considered as the mother of all languages.

7.What is the purpose of printf() and scanf() in C Program?

Ans: printf() is used to print the values on the screen. To print certain values, and on the other
hand, scanf() is used to scan the values. We need an appropriate datatype format specifier for
both printing and scanning purposes. For example,

 %d: It is a datatype format specifier used to print and scan an integer value.
 %s: It is a datatype format specifier used to print and scan a string.
 %c: It is a datatype format specifier used to display and scan a character value.
 %f: It is a datatype format specifier used to display and scan a float value.

8. What is an array?

Ans. The array is a simple data structure that stores multiple elements of the same datatype in
a reserved and sequential manner. There are three types of arrays, namely,

 One Dimensional Array


 Two Dimensional Array
 Multi-Dimensional Array

9. What is /0 character?

Ans: The Symbol mentioned is called a Null Character. It is considered as the terminating
character used in strings to notify the end of the string to the compiler.

10.What is a C token?
he smallest individual units in C are known as C tokens. There are six types of tokens in C,
 Keywords
 Constants
 Identifiers
 Strings
 Operators
 Special symbols.
11. What is a C keyword?
Predefined reserved words with fixed meanings are called keywords. Keywords are the
building blocks for program statements.
12.How many reserved keywords are there in C?

There are 32 reserved keywords in C. They are

auto break case char

const continue do default

double else enum extern

float for goto if

int long register return

short signed sizeof static

struct switch typedef union

unsigned void volatile while

13. What is an identifier in C and What is a variable?

The names of variables, functions, and arrays are referred to as identifiers. These are user-
defined names consisting of a sequence of letters and digits. Identifiers must be unique.
A variable is a user-defined name given to memory locations that can be used to store data. A
variable may take different values at different times during the execution of a program.

14. What do you mean by the scope of a variable?

The part of the code where a declared variable can be accessed directly is called the scope of
the variable.

15. What is a constant and What is meant by variable initialization?

Fixed values that do not change throughout program execution are called constants.

Assigning a value to a variable once declared is called the initialization of a variable.

16. What are the data types present in C?


C supports five primary
(fundamental) datatypes namely integer(int), character(char), floating-point(float), double-
precision floating-point(double) and void(void).

Derived types are data types that are derived from fundamental data types. Arrays, pointers,
function types, structures, and so on are examples.
User-defined datatypes – structures, unions, enum.

17. What is an operator?


An operator is a symbol that instructs a computer to perform certain operations. Operators are
typically used as part of mathematical or logical expressions.
What are the operators available in C?
Aritmetic Operators + – * / %

Relational Operators < <= > >= == !=

Logical Operators && || !

Assignment Operator += -= *= /= %=

Increment and Decrement Operator ++ —

Bitwise Operator & | ^ ` << >>

Conditional Operator ?:

Special Operator sizeof . ->

18. What is operator precedence?

The order in which C evaluates expressions is called operator precedence.

19. What is the modulus(%) operator?

The modulo division (%) operator produces the remainder of an integer division.

20. What is the difference between = and == operator in C?


= is assignment operator to assign values.

== is the comparison operator used to check whether the value or expression on both the side
are same (return 0) or not ((return 1)

21.What are the different forms of if statements that can be implemented in C?


 Simple if statement.
 if….else statement.
 Nested if….else statement.
 else if ladder.
22. What is looping?

The process of executing a sequence of statements repeatedly until some conditions for
termination of the loop is satisfied is called looping.

23. What are the loop control statements provided in C?


 The
while
statement.
 The
Do and Do while
statement.
 The
for
statement.
24. What is the use of the break statement?

The

break
statement can be used to accomplish an early exit from a loop. When a

break
statement is encountered inside a loop, the loop is immediately exited and the program
continues with the statement immediately following the loop.
25. What is the use of the continue statement?

The

continue
statement is used to skip a part of a loop. It causes the loop to be continued with the next
iteration after skipping any statements in between.
26. What is an array?
An Array is a collection of variables of a similar type that are referenced by a common name.
There are three types of arrays, namely,
 One Dimensional Array
 Two Dimensional Array
 Multi DImensional Array
27. Define String?

A sequence of characters that are treated as a single data item is called a string.
28. What is the important string handling functions in C?
 strcpy()
– String assignment function.

 strlen()
– Returns the number of characters in the string.

 strcmp()
– Compares two strings.

 strcat()
– Concatenate two strings.

 strstr()
– Used to locate substring.
29. What is a function?

A block of program code that performs a particular task is called a function.

How is a Function declared in C Language?

Ans: A function in C language is declared as follows,

1return_type function_name(formal parameter list)


2{
3 Function_Body;
4}

30.Differentiate between call by value and call by reference.

Ans:

Factor Call by Value Call by Reference

Actual arguments cannot be changed and remain Operations are performed on actual arguments,
Safety
safe hence not safe

Memory Separate memory locations are created for actual Actual and Formal arguments share the same
Location and formal arguments memory space.

Arguments Copy of actual arguments are sent Actual arguments are passed
What are the different storage class specifiers in C?

Ans: The different storage specifiers available in C Language are as follows:

 auto
 register
 static
 extern

31.Difference between while and do while.

BASIS FOR
WHILE DO-WHILE
COMPARISON

General Form while ( condition) { do{

statements; //body of loop .

} statements; // body of loop.

} while( Condition );

Controlling Condition In 'while' loop the controlling condition In 'do-while' loop the controlling condition

appears at the start of the loop. appears at the end of the loop.

Iterations The iterations do not occur if, the The iteration occurs at least once even if the

condition at the first iteration, appears condition is false at the first iteration.

false.

Alternate name Entry-controlled loop Exit-controlled loop

Semi-colon Not used Used at the end of the loop

32. What is the difference between library functions and user-defined functions?

The functions that are already defined in the C library are called library functions(Built-in
functions). They are stored in different header files and these functions cannot be modified by
the user. To use a library function in a program, the user has to include the corresponding
header file in the program. Some of the library functions in C include

printf(), scanf(), getch(), sqrt(), etc.


The function that has to be defined by the user at the time of writing a program is called user-
defined functions.

33. What is the difference between a formal parameter and an actual parameter?

The parameters used in function definitions are called formal parameters and those used in
function calls are called actual parameters. The formal parameters list declares the variables
that will receive the data sent by the calling program.

34.Distinguish between automatic and static variables.

All local variables that are declared inside a function are known as auto variables unless not
specified. That is, by default a local variable is an auto variable. An auto variable is created
each time when the function is called and destroyed when the program’s execution leaves the
function.

A static variable is similar to an automatic variable. A static variable is declared once and
only destroys when the execution of the program finishes.
AUTOMATIC VARIABLES STATIC VARIABLES

All local variables are automatic by default. Using the keyword static keyword must be used to declare a static
auto is optional. varibale.

The scope of an automatic variable is always local to the function The scope of an static variable is always local to the
in which it is declared. function.

A static variable is only initialized once, when the


Automatic variables are created when the function is called.
program is compiled.

Automatic variables are destroyed when the execution of the The value of a static variable persists until the end of
function is completed. the program.

35. What do you mean by scope, visibility, and lifetime of a variable?

The region of a program in which a variable is available for use is called the scope of the
variable.

The ability of a program to access a variable from the memory is the visibility of a variable.

The duration of time in which a variable exists in the memory during execution is the lifetime
of a variable.

36. How does a structure differ from an array?

An array is a collection of data elements of the same type. Structures can have elements of
different types.

An array is a derived data type whereas a structure is a user-defined data type.

An array can be used as a built-in datatype. All we have to do is declare and use the array.
But in the case of a structure, we have to design and declare it as a data structure before the
structure variables are declared and used.

37. Distinguish between a structure and union.

Both structure and union are user-defined data types in C. The major difference between a
structure and a union is in terms of storage. In structures, each member has its own storage
location, but all the members of a union share the same location. That is a union can handle
only one member at a time.

38. What are the size of a structure and a union?

The total size of the structure is the sum of the size of every data member. The total size of a
union is the size of the largest data member.
39. What is meant by nested structures and arrays of structures?

The individual members of a structure can be other structures as well, such structure is called
a nested structure. That is, a structure may contain another structure as its member.

It is possible to declare an array of structures. The array will have individual structures as its
elements.

40. What is a pointer?

Pointers are a special type of variable that is used to store the address of another variable as
their values.

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

42. What is a conditional statement?

Conditional Statement (also called Condition) is a feature of programming language , which


allows it to perform actions depending upon some conditions provided by the programmer.
Conditional statement controls the sequence of statements depending on the condition.

43. What are the different types of conditional statements?

The different types of conditional statements in C language are as follows: 1. if statement 2. if


else statement 3. else if statement 4. nested if-else statement 5. switch statement 6. goto
statement

44.Explain about simple If statement?

The if statement gives the user the choice of executing a statement (possibly compound) if
the expression is evaluated to true or skipping it is the expression is evaluated to false.
Syntax: An if statement in C is generally in the following form:
if (expression)

{ Statement; }

The statement is executed if and only if the expression is true

. What is use of if-else statement?

C language also lets one choose between two statements by using the if-else structure.
Syntax: if (expression)

{ Statement 1 }

Else

{ Statement 2 }

In this case, if the expression is true, then the statement 1 is executed. Otherwise, statement 2
is executed.

45.What is the use of the function in C?

Uses of C function are:

 C functions are used to avoid the rewriting the same code again and again in our
program.
 C functions can be called any number of times from any place of our program.
 When a program is divided into functions, then any part of our program can easily be
tracked.
 C functions provide the reusability concept, i.e., it breaks the big task into smaller
tasks so that it makes the C program more understandable.

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


When a copy of the value is passed to When a copy of the value is passed to
Description the function, then the original value is
the function, then the original value is
not modified. modified.
Actual arguments and formal Actual arguments and formal
Memory
arguments are created in separate arguments are created in the same
location
memory locations. memory location.
In this case, actual arguments remain In this case, actual arguments are not
Safety
safe 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.
47. What do you mean by an Array?

 Array is a set of similar data type.


 Arrays store multiple variables with the same type.
 Arrays are always fixed

48. How to create an Array?

 An Array is declared similar to how a variable is declared, but you need to add [] after
the type.
 Example: int [] intArray;

49. Advantages and disadvantages of Array?

Advantages:

 We can put in place other data structures like stacks, queues, linked lists, trees,
graphs, etc. in Array.
 Arrays can sort multiple elements at a time.
 We can access an element of Array by using an index.

Disadvantages:

 We have to declare Size of an array in advance. However, we may not know what size
we need at the time of array declaration.
 The array is static structure. It means array size is always fixed, so we cannot increase
or decrease memory allocation.

50. Can you declare an array without assigning the size of an array?
No we cannot declare an array without assigning size.

 If we declare an array without size, it will throw compile time error


 Example: marks = new int []; //COMPILER ERROR

51. Difference between structure and union.

Structure
Structure is a user defined datatype. It is used to combine different types of data into a single
type. It can have multiple members and structure variables. The keyword “struct” is used to
define structures in C language. Structure members can be accessed by using dot(.) operator.
Here is the syntax of structures in C language,
struct structure_name {
member definition;
} structure_variables;
Union
Union is also a user defined datatype. All the members of union share the same memory
location. Size of union is decided by the size of largest member of union. If you want to use
same memory location for two or more members, union is the best for that.
Unions are similar to the structure. Union variables are created in same manner as structure
variables. The keyword “union” is used to define unions in C language.
Here is the syntax of unions in C language,
union union_name {
member definition;
} union_variables;

52. Difference Between Array and Structure

Array
 It refers to a collection that consists of elements of homogenous/same data
type.
 It uses subscripts/ ‘[ ]’ (square brackets) to access the elements.
 It is a pointer that points to the first element of the collection.
 The array objects can’t be instantiated.
 The size of array is fixed based on the number of elements in the array.
 This size is the product of number of elements and size of every element.
 Bit field is not possible in an array.
 It is considered as a primitive data type.
 Traversing through and searching for elements in an array is quick and easy.
 It can be declared using the ‘[ ]’.
 Array size is fixed and is basically the number of elements multiplied by the
size of an element.
 It is stored in contiguous memory locations.

Example
data_type array_name[size];

Structure
 It is a collection that consists of elements of heterogenous/dissimilar data
types.
 It uses the ‘.’ (dot operator) to access the elements.
 It isn’t a pointer.
 It can be instantiated.
 The size is not fixed.
 This is because the elements in a structure can be of different data types and
sizes.
 Bit field is possible to create in a structure.
 It can be declared using the ‘struct’ keyword.
 It is a user-defined datatype.
 Traversing and searching through a structure is slow and complex.
 They may or may not be stored in a contiguous memory location.

Example
struct sruct_name {
data_type1 ele1;
data_type2 ele2;
};
_

You might also like