0% found this document useful (0 votes)
107 views7 pages

C Program Viva1

This document contains a set of questions and answers related to C programming. It covers basic concepts like data types, operators, functions, arrays, strings and more advanced topics like recursion, pointers, structures and unions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views7 pages

C Program Viva1

This document contains a set of questions and answers related to C programming. It covers basic concepts like data types, operators, functions, arrays, strings and more advanced topics like recursion, pointers, structures and unions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

lOMoARcPSD|42531642

C program viva1

Bachelor of computer applications (Bangalore University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Dr. Lissy Devasahayam ([email protected])
lOMoARcPSD|42531642

C programming viva Questions and Answers


1. What is C?
C is a high-level, general-purpose, procedural programming language.
2. Who developed C language?
Dennis Ritchie.
3. When was C language developed?
C language was developed in 1970 at Bell Laboratories.
4. What is a C token?
The 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.
5. What is a C keyword?
Predefined reserved words with fixed meanings are called keywords. Keywords are the building blocks for
program statements.
6. How many reserved keywords are there in C?
There are 32 reserved keywords in C. They are
auto break case

const continue do d

double else enum

float for goto

int long register

short signed sizeof

struct switch typedef

unsigned void volatile


7. What is an identifier in C?
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.
8. What is a variable?
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.
9. 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.
10. What is a constant?
Fixed values that do not change throughout program execution are called constants.
11. What is meant by variable initialization?
Assigning a value to a variable once declared is called the initialization of a variable.
12. 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.
13. What is an operator?

Downloaded by Dr. Lissy Devasahayam ([email protected])


lOMoARcPSD|42531642

An operator is a symbol that instructs a computer to perform certain operations. Operators are typically used
as part of mathematical or logical expressions.
14. 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 . ->


15. What is operator precedence?
The order in which C evaluates expressions is called operator precedence.
16. What is the modulus(%) operator?
The modulo division (%) operator produces the remainder of an integer division.
17. What is the difference between integer arithmetic, real arithmetic, and mixed-mode arithmetic?
When the operands in a single arithmetic expression are both integers, then the operation is known
as integer arithmetic. Integer arithmetic always produces an integer value as output. All the examples in the
above table are integer arithmetic. For example:
12 / 10 = 1
Real arithmetic refers to arithmetic operations that will use only real operands. The operator % cannot be
used with real operands. For example:
3.0 / 2.0 = 1.5
Mixed-mode arithmetic expressions are those in which one of the operands is real and the other is an
integer. Since one of the operands is of real type, then the result is always a real number. For example:
12 / 10.0 = 1.2
18. What is the difference between = and == operator in C?
==
is the comparison operator used to check whether the value or expression on the
19. What is the use of printf() and scanf() functions in C?
The
scanf()
function is used to input data through the keyboard. It is a general input function available in C. The
printf()
function can be used to display values of variables and results of expressions on the screen.
20. 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.
21. 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.
22. What are the loop control statements provided in C?
 The
while

Downloaded by Dr. Lissy Devasahayam ([email protected])


lOMoARcPSD|42531642

statement.
 The
do
statement.
 The
for
statement.
23. 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.
24. 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.
25. 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

Intermediate C Interview Questions and Answers


26. Define String?
A sequence of characters that are treated as a single data item is called a string.
27. 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.
28. What is a function?
A block of program code that performs a particular task is called a function.
29. 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()
,

Downloaded by Dr. Lissy Devasahayam ([email protected])


lOMoARcPSD|42531642

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.
30. 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.
31. What is recursion?
A technique where a function calls itself is known as recursion.
32. 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 musbe used to declare a static varibale.
auto is optional.

The scope of an automatic variable is always


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

Automatic variables are created when the A static variable is only initialized once, when the program is
function is called. compiled.

Automatic variables are destroyed when the The value of a static variable persists until the end of the
execution of the function is completed. program.
33. 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.
34. 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.
35. 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.
36. 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.
37. 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.
38. What is a pointer?

Downloaded by Dr. Lissy Devasahayam ([email protected])


lOMoARcPSD|42531642

Pointers are a special type of variable that is used to store the address of another variable as their values.
39. What is type conversion?
The process of converting a variable of one data type into another is referred to as typecasting. Casting
allows you to make this type of conversion explicit, or to force it when it wouldn’t normally happen.
40. What is the difference between a void pointer and a null pointer?
A pointer that holds a null value is called a null pointer. When a pointer has a null value it is not pointing
anywhere. A void pointer is a type of pointer that points to some data location in storage, which doesn’t have
any specific type.
That is null pointer is a value, while the void pointer is a type.
41. How does an append mode differ from a write mode in file management?
When the mode is ‘write’, a file is created if the file does not exist. If that file already exists, then the contents
are deleted before starting writing.
When the mode is ‘append’, the file is opened with current contents safe. If the file does not exist, then a file
with the specified name is created.
42. What is the significance of EOF in files?
‘EOF’ is a specific designation for a file marker that indicates the end of the data.
43. What is dynamic memory allocation?
The process of allocating memory at runtime is known as dynamic memory allocation.
44. What is the difference between a macro and a function in C?
Macros Functions

All the macros will be processed before the program


Functions are not preprocessed but compiled.
compiles.

Macros do not check for compilation errors which


Function checks for compilation errors.
leads to unexpected output.

Before Compilation, the macro name is replaced by


During function call, transfer of control takes place.
macro value.

Faster in execution. A bit slower in execution than Macros.


45. What is a double pointer?
When a pointer holds the address of another pointer then such type of pointer is known as double pointer.
Advanced C Interview Questions and Answers
46. What are the two ways of passing parameters to functions?
 Pass by Value – The values of actual parameters are copied to the variables in the parameter list of
the called function. Any changes to the parameter in the called function have no effect on data in the calling
function. That is the called function works on the copy and not on the original values.
 Pass by Reference – The memory addresses of the variable rather than the copies of values are sent
to the called function. Thus any changes made to the parameter are also made to the original variable.
47. What are the rules for initializing structures?
The rules to keep in mind while initializing structure variables are,
 We cannot initialize individual data members inside the structure definition.
 The order of values enclosed in braces must match the order of members in the structure definition.
 It is permitted to initialize only the first few members and leave the remaining blank. The uninitialized
members should be at the end of the list.
 The uninitialized members will have default values based on the data type.
48. What is conditional compilation?
Conditional compilation is a feature of the C preprocessor which can be used to switch on or off a particular
line or group of lines in a program. The compiler control directives used for this are,
 #if
 #else
 #elif

Downloaded by Dr. Lissy Devasahayam ([email protected])


lOMoARcPSD|42531642

 #endif
 #ifdef
 #ifndef
 #undef
 #pragma
 #error
#49. What is the difference between functions and parameterized macros?
Macros Functions

All the macros will be processed before the program compiles. Functions are not preprocessed but compiled.

Macros do not check for compilation errors which leads to


Function checks for compilation errors.
unexpected output.

Before Compilation, the macro name is replaced by macro value. During function call, transfer of control takes place.

Faster in execution. A bit slower in execution than Macros.


50. What are the typical applications of pointers in developing programs?
 To pass arguments by reference.
 For accessing array elements.
 To return multiple values.
 Dynamic memory allocation.
 To implement data structures.
 To do system-level programming where memory addresses are useful.
51. What are near, far, and huge pointers?
Near pointer is used to store 16-bit addresses means within the current segment on a 16-bit machine. The
limitation is that we can only access 64kb of data at a time.
A far pointer is typically 32-bit, which includes a segment selector, making it possible to point the addresses
outside of the default segment.
The huge pointer is also 32-bit and can access outside segments. In far pointer, the segment part cannot be
modified, but in Huge it can be.
52. What is a dangling pointer in C?
A pointer pointing to a non-existing memory location is called a dangling pointer. A dangling pointer is a
pointer that has a value that refers to some memory location that is not valid or does not exists.
53. What is a wild pointer in C?
A pointer in C that is not initialized either by the compiler or programmer is known as a wild pointer.
Uninitialized pointers behavior is totally undefined because it may point to some arbitrary location that can be
a cause of the program crash.
54. What is the difference between malloc() and calloc()?
malloc()
allocates the requested size of bytes and returns a pointer to the first byte of the allocated space.
calloc()
allocates space for an array of elements, initializes them to zero, and then returns a pointer to the memory.
55. What do you mean by Memory Leak?
A memory leak occurs when memory is allocated but not released back to the operating system. Memory
leakage increases unwanted memory usage.
56. What are command line arguments?
Command line arguments are simply arguments that are specified after the name of the program in the
system’s command line, and these argument values are passed on to your program during program
execution.

Downloaded by Dr. Lissy Devasahayam ([email protected])

You might also like