Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Language Questions and Answers: Visit For More: WWW - Learnengineering.In

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

Visit For More : www.LearnEngineering.

in

C Language Questions and Answers

1. What is C language?
C is a programming language developed at AT&T's Bell Laboratories of USA in 1972. The C
programming language is a standardized programming language developed in the early
1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has
since spread to many other operating systems, and is one of the most widely used
programming languages.

2. What are the types of constants in C?


In C language two types of constants are available:
Primary constants
Secondary constants

3. What are the types of C instructions?


There are basically three types of instructions in C:
Type Declaration Instruction
Arithmetic Instruction
Control Instruction

4. What is a pointer?
Pointers are variables which stores the address of another variable. That variable may be a
scalar (including another pointer), or an aggregate (array or structure). The pointed-to
object may be part of a larger object, such as a field of a structure or an element in an
array.

5. What is an array?
Array is a variable that hold multiple elements which has the same data type.

6. Differentiate between arrays and pointers?


Pointers are used to manipulate data using the address. Pointers use * operator to access
the data pointed to by them.
Array is a collection of similar data type. Array use subscripted variables to access and
manipulate data. Array variables can be equivalently written using pointer expression.

7. What is “this” pointer?


The “this” pointer is a pointer accessible only within the member functions of a class,
struct,or union type. It points to the object for which the member function is called. Static
member functions do not have a “this” pointer.

8. What are the uses of a pointer?


Pointer is used in the following cases
It is used to access array elements.
63

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

It is used for dynamic memory allocation.


It is used in Call by reference.
It is used in data structures like trees, graph, linked list etc.

9. What is the purpose of main() function?


The function main() invokes other functions within it. It is the first function to be called
when the program starts execution.
It is the starting function.
It returns an int value to the environment that called the program.
Recursive call is allowed for main( ) also.
It is a user-defined function.

10. What are the different storage classes in C?


There are four types of storage classes in C language.
Automatic
Extern
Register
Static

11. What is a structure?


Structure constitutes a super data type which represents several different data types in a
single unit. A structure can be initialized if it is static or global.

12. Define Constructors?


A constructor is a member function with the same name as its class. The constructor is
invoked whenever an object of its associated class is created. It is called constructor
because it constructs the values of data members of the class.

13. Define destructors?


A destructor is called for a class object when that object passes out of scope or is explicitly
deleted. A destructors as the name implies is used to destroy the objects that have been
created by a constructors. Like a constructor, the destructor is a member function whose
name is the same as the class name but is preceded by a tilde.

14. What is the use of default constructor?


A constructor that accepts no parameters is called the default constructor. If no
userdefined constructor exists for a class A and one is needed, the compiler implicitly
declares a default parameter less constructor A::A(). This constructor is an inline public
member of its class. The compiler will implicitly define A::A() when the compiler uses this
constructor to create an object of type A. The constructor will have no constructor
initializer and a null body.

64

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

15. What is a macro?


Macros are the identifiers that represent statements or expressions.

16. What is the difference between #include< > and #include “ ”?


#include< > ----> specifically used for built in header files.
#include “ ” ----> Specifically used for used for user defined/created header file.

17. What are the advantages of the functions?


It reduces the Complexity in a program by reducing the code.
Functions are easily understanding and reliability and execution is faster.
It also reduces the Time to run a program. In other way, it’s directly proportional to
Complexity.
It’s easy to find-out the errors due to the blocks made as function definition outside the
main function.

18. How do declare an array?


We can declare an array by specify its data type, name and the number of elements the
array holds between square brackets immediately following the array name. syntax :
data_type array_name[size];

19. What are the differences between structures and union?


A structure variable contains each of the named members, and its size is large enough to
hold all the members. Structure elements are of same size.
A Union contains one of the named members at a given time and is large enough to hold
the largest member. Union element can be of different sizes.

20. What is the difference between an Array and a List?


The main difference between an array and a list is how they internally store the data
whereas Array is collection of homogeneous elements. List is collection of heterogeneous
elements.

21. What is the difference between a string copy (strcpy) and a memory copy (memcpy)?
The strcpy() function is designed to work exclusively with strings. It copies each byte
of the source string to the destination string and stops when the terminating null
character () has been moved.
On the other hand, the memcpy() function is designed to work with any type of data.
Because not all data ends with a null character, you must provide the memcpy() function
with the number of bytes you want to copy from the source to the destination.

22. What is the difference between const char*p and char const* p? const char*p - p is
pointer to the constant character. i.e value in that address location is constant.
const char* const p - p is the constant pointer which points to the constant string, both
value and address are constants.

23. What is the purpose of realloc()?

65

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Realloc(ptr,n) function uses two arguments.


The first argument ptr is a pointer to a block of memory for which the size is to be altered.
The second argument n specifies the new size. The size may be increased or decreased.

24. What is the use of typedef?


The typedef help in easier modification when the programs are ported to another machine.
A descriptive new name given to the existing data type may be easier to understand the
code.

25. What are the differences between new and malloc?


New initializes the allocated memory by calling the constructor. Memory allocated with
new should be released with delete.
Malloc allocates uninitialized memory.
The allocated memory has to be released with free. New automatically calls the
constructor while malloc(dosen’t)

26. What is the difference between strdup and strcpy?


Both copy a string. strcpy wants a buffer to copy the string. strdup allocates a buffer using
malloc(). Unlike strcpy(), strdup() is not specified by ANSI.

27. What is this pointer?


It is a pointer that points to the current object. This can be used to access the members of
the current object with the help of the arrow operator.

28. What is recursion?


A recursion function is one which calls itself either directly or indirectly it must halt at a
definite point to avoid infinite recursion.

29. What are the characteristics of arrays in C?


An array holds elements that have the same data type.
Array elements are stored in subsequent memory locations
Two-dimensional array elements are stored row by row in subsequent memory locations.
Array name represents the address of the starting element

30. Differentiate between for loop and a while loop? What are it uses?
For executing a set of statements fixed number of times we use for loop while when the
number of iterations to be performed is not known in advance we use while loop.

31. What is the difference between printf(...) and sprintf(...)? printf(....) -------------> is
standard output statement sprintf(......)-----------> is formatted output statement.

32. What is an explicit constructor?

66

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

A conversion constructor declared with the explicit keyword. The compiler does not use an
explicit constructor to implement an implied conversion of types. Explicit constructors are
simply constructors that cannot take part in an implicit conversion.

33. What is copy constructor?


Copy constructor is a constructor function with the same name as the class and used to
make deep copy of objects.

34. What is the difference between malloc and calloc?


Malloc() is use for memory allocation and initialize garbage values. malloc() for allocating
the single block of memory.
Calloc() is same as malloc() but it initialize 0 value. calloc() for allocating multiple blocks
of memory.

35. What is null pointer?


NULL pointer is a pointer which is pointing to nothing.
Examples :
int *ptr=(char *)0;
float *ptr=(float *)0;

36. What is dynamic array?


The dynamic array is an array data structure which can be resized during runtime which
means elements can be added and removed.

37. What are macros? What are its advantages and disadvantages?
Macros are abbreviations for lengthy and frequently used statements. When a macro is
called the entire code is substituted by a single line though the macro definition is of
several lines.
The advantage of macro is that it reduces the time taken for control transfer as in case of
function. The disadvantage of it is here the entire code is substituted so the program
becomes lengthy if a macro is called several times.

38. What are register variables? What are the advantages of using register variables? If a
variable is declared with a register storage class, it is known as register variable. The
register variable is stored in the CPU register instead of main memory. Frequently used
variables are declared as register variable as it’s access time is faster.

39. What is storage class? What are the different storage classes in C?
Storage class is an attribute that changes the behavior of a variable. It controls the
lifetime,scope and linkage. The storage classes in c are auto, register, and extern, static,
typedef.

40. What the advantages of using Unions?


When the C compiler is allocating memory for unions it will always reserve enough room
for the largest member.

67

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

41. In C, why is the void pointer useful? When would you use it?
The void pointer is useful because it is a generic pointer that any pointer can be cast into
and back again without loss of information.

42. What is the difference between the functions memmove() and memcpy()? The
arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.

43. Can a Structure contain a Pointer to itself?


Yes such structures are called self-referential structures.

44. What is dynamic memory allocation?


A dynamic memory allocation uses functions such as malloc() or calloc() to get memory
dynamically. If these functions are used to get memory dynamically and the values
returned by these function are assigned to pointer variables, such a way of allocating
memory at run time is known as dynamic memory allocation.

45. What is pointer to a pointer?


If a pointer variable points another pointer value. Such a situation is known as a pointer to
a pointer.
Example :
int *p1, **p2,
v=10; P1=&v;
p2=&p1;
Here p2 is a pointer to a pointer.

46. What is a function?


A large program is subdivided into a number of smaller programs or subprograms. Each
subprogram specifies one or more actions to be performed for the larger program. Such
sub programs are called functions.

47. What is an argument?


An argument is an entity used to pass data from the calling to a called function.

48. What is the difference between syntax vs logical error?


Syntax Error
These involve validation of syntax of language.
Compiler prints diagnostic message.
Logical Error
Logical error are caused by an incorrect algorithm or by a statement mistyped in such a
way that it doesn’t violet syntax of language.
Difficult to find.

49. Explain enumerated types.

68

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Enumerated types allow the programmers to use more meaningful words as values to a
variable.
Each item in the enumerated type variable is actually associated with a numeric code.

50. Differentiate between the expression “++a” and “a++”?


With ++a, the increment happens first on variable a, and the resulting value is used.
This is called as prefix increment.
With a++, the current value of the variable will be used in an operation. This is called as
postfix increment.

51. What is preprocessor?


The preprocessor is a program which is executed before the compilation of a source
program written by the user. The preprocessor directives begines with hash (#) followed
by the command. e.g #include – it is a directive to include file.

52. What is lvalue and rvalue?


The expression appearing on right side of the assignment operator is called as rvalue.
Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The
lvalue should designate to a variable not a constant.

53. What is typecasting?


Typecasting is a way to convert a variable/constant from one type to another type.

69

Visit For More : www.LearnEngineering.in


C Language LAB VIVA Questions :-
1. Who developed C language?
C language was developed by Dennis Ritchie in 1970 at Bell Laboratories.
2. Which type of language is C?
C is a high – level language and general purpose structured
programming language. 3. What is a compiler?
Compile is a software program that transfer program developed in
high level language intoexecutable object code 4. What is IDE?
The process of editing, compiling, running and debugging is managed
by a single integratedapplication known as Integrated Development
Environment (IDE) 5. What is a program?
A computer program is a collection of the instructions necessary to solve
a specific problem.
Prepare for Coding Interviews
Join PrepBytes - Learn, Practice, Get mentorship & Get companies.
PrepBytes
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf
https://engineeringinterviewquestions.com/c-language-viva-questions-with-answers-cse/ 3/12
6. What is an algorithm?
The approach or method that is used to solve the problem is known as algorithm.
7. 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
8. 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.
9.What is a Keyword?
Keywords are building blocks for program statements and have fixed meanings
and thesemeanings cannot be changed.
10.How many Keywords (reserve words) are in C?
There are 32 Keywords in C language.
C Language LAB VIVA
Questions
11.What is an Identifier?
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf
https://engineeringinterviewquestions.com/c-language-viva-questions-with-answers-cse/ 4/12
Identifiers are user-defined names given to variables, functions and arrays.
12.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).
13.What are the Back Slash character constants or Escape
sequence charactersavailable in C?
Back Slash character constant are \t, \n, \0 14.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 15.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)
16.How to declare a variable?
The syntax for declaring variable isdata type variable_name-1, variable_name-
2,….variable_name-n;
17.What is meant by initialization and how we initialize a variable?
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf https://engineeringinterviewquestions.com/c-language-
viva-questions-with-answers-cse/ 5/12
While declaring a variable assigning value is known as initialization.
Variable can beinitialized by using assignment operator (=).
18.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.
19.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) 20. What is RAM ?
RAM – Random Access Memory is a temporary storage medium in a
computer. RAM is a volatile memory i.e all data stored in RAM will be erased
when the computer is switched off.
21. What do mean by network ? Prepare
for Coding Interviews
Join PrepBytes - Learn, Practice, Get mentorship & G companies.
PrepBytes
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf
https://engineeringinterviewquestions.com/c-language-viva-questions-with-answers-cse/ 6/12
Computer networking refers to connecting computers to share data, application
software and hardware divices. Networks allow sharing of information among
various computers and permit users to share files 22. List a few unconditional
control statement in C.
1. break statement
2. continue statement
3. goto statement
4. exit() function 23. What is an array ?
An array is a collection of values of the same data type. Values in array
are accessed using array name with subscripts in brackets[]. Synatax of
array declaration is data type array_ name[size]; 24. What is
Multidimensional Arrays
An array with more than one index value is called a multidimensional
array. To declare a multidimensional array you can do follow syntax
data type array_ name[] [] []….; 25. Define string ?
An array of characters is known as a string.for example char st[8];
this statement declares a string array with 80 characters .
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf https://engineeringinterviewquestions.com/c-language-
viva-questions-with-answers-cse/ 7/12
26. Mention four important string handling functions in C languages
.
There are four important string handling functions in C languages .
strlen();
trcpy(); strcat();
strcmp();
The header file #include is used when these functions are called in a C program.
27. Explain about the constants which help in debugging?
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf https://engineeringinterviewquestions.com/c-language-
viva-questions-with-answers-cse/ 8/12
A #if directive test can be offered with #else and #else if directives.
This allows conditional branching of the program to run sections of the
code according to the result. Constants defined with a #define
directive can be undefined with the #undef directive. The #ifdef
directive has a companion directive #ifndef. These commands can be
useful when debugging problem code to hide and unhide sections of
the program.
28. Define and explain about ! Operator?
The logical operator ! NOT is a unary operator that is used before a
single operand. It returns the inverse value of the given operand so if the
variable “c” had a value of true then! C would return value of false. The
not operator is very much useful in C programs because it can change
the value of variables with successful iterations. This ensures that on
each pass the value is changed.
29. What is operator precedence?
Operator precedence defines the order in which C evaluates expressions.
e.g. in the expression a=6+b*3, the order of precedence determines
whether the addition or the multiplication is completed first. Operators
on the same row have equal precedence.
30. Explain about the functions strcat() and strcmp()?
This function concatenates the source string at the end of the target
string. Strcmp() function compares two strings to find out whether they
are the same or different. The two strings are compared character by
character until there is a mismatch or end of one of the strings is
reached, whichever occurs first. If in case two strings are identical, a
value of zero is returned. If there is no matches between two strings
then a difference of the two non matching values are returned
according to ASCII values.
31. Define function
7/29/2021 300+ TOP C Language LAB VIVA Questions with Answers Pdf
https://engineeringinterviewquestions.com/c-language-viva-questions-with-answers-cse/ 9/12
A function is a module or block of program code which deals with a
particular task. Each function has a name or identifier by which is
used to refer to it in a program. A function can accept a number of
parameters or values which pass information from outside, and
consists of a number of statements and declarations, enclosed by curly
braces { }, which make up the doing part of the object 32.
Differentiate built-in functions and user – defined functions.
Built – in functions are used to perform standard operations such as
finding the square root of a number, absolute value and so on. These are
available along with the C compiler and are included in a program using
the header files math.h, s tring.h and so on.
User defined functions are written by the user or programmer to
compute a value or perform a task. It contains a statement block which
is executed during the runtime whenever it is called by the main
program.
33. Distinguish between actual and formal arguments.
Actual arguments are variables whose values are supplied to the function
in any function call. Formal arguments are variables used to receive the
values of actual arguments from the calling program.
34. Explain the concept and use of type void.
A function which does not return a value directly to the calling program
is referred as a void function. The void functions are commonly used to
perform a task and they can return many values through global
variable declaration.
35. What is recursion ?
A function calling itself again and again to compute a value is referref to as
recursive function or recursion. Recursion is useful for branching processes and is
effective where terms are generated successively to compute a value.

The C language was originally developed from B language.


2. C language was implemented in the year 1972
3. C language was implemented at the Bell laboratories.
4. The UNIX operating system was written in UNIX language.
5. A C program is basically a collection of Functions
6. C language is well suited for Structure programming.
7. A newline character instructs the computer to move the control to the next line.
8. C program execution begins from main()
9. Local variable which exists and retains its value even after the control is transferred to the calling
function is,static.storage class.
10. An extern storage class can be used to declare global variable known to all the functions in the 11.
The relational expression 5.5<=10 is---------------- 12.
The relational expression -30>=0 is------------.
13. The operator “- -’’ is known as ------------ operator.
14. The operator “++’’ is known as -----------operator.
15. The operator “++’’ adds the value ------------ to the operand.
16. The operator “- -’’ subtracts the value ------------ From the operand.
17. The ------------ is equivalent to a = a+1.
18. The ------------ is equivalent to a + =1.
19. The ------------ is equivalent to a = a-1.
20. The ----------- is equivalent to a- = 1.
21. Consider the following statement: a= ++y; y=5,then the value of a is ------------ - 6
22. Consider the following statement: a=y++; y=5, then the value of a is ------------ -5
23. Consider the following statement: a=10; b=++a; then the value of b is ------------ -11
24 Consider the following statements:a=10;b=a++;then the value of b is ---------------- -10
25. Consider the following statement:a =++b;b=199,The value of a is ------------ -200 26.
The -----------operator can be used to determine the length of array and structures.
27. The -----------operator can be used to allocate memory space dynamically to variables during
Execution of a program.
28. .......function returns the arc cosine of x.
29. ------------function returns the arc sine of x.
30. ------------.function returns the arc tangent of x.
31. ------------function returns the cosine of x.
32. -----------function returns the sine of x.
33. --------------function returns the tangent of x.
34. ------------function returns hyperbolic cosine of x.
35. ----------------function returns hyperbolic sine of x.
36. ----------------.function returns hyperbolic tangent of x.
37. -------------.function is used to round off the value of x to the nearest integer.
38. ------------returns the exponential of x.
39. -----------function returns the absolute value of x.
40. Determine the value of the following logical expression when x=10, y=15 and z=20.
Expression Result X >y &&x x ll y > z -------------
42. Determine the value of the following logical expression when x=10, y=15 and z=20.
Expression Result X+y > z && z > y -------------------
43. Determine the value of the following logical expression when x=10, y=15 and z=20.
Expression Result X! = yll y = = z -------------------
44. The standard mathematical functions are included in the ------------..header file.
45. ----------------function can be used to read a single character.
46. In C, language ------------checks whether the input value of the argument c is an alphabet or not.
47. --------------function checks whether c is lower case letter or not. CS8261 –C Programming Lab
Department of IT 2020-2021
St. Joseph’s Institute of Technology 44
48. -------------function checks whether c is upper case letter or not.
49. ------------checks whether c is an alphanumeric character or not.
50. Repeating a set of statements for a specific number of times is called looping structure.
51. An immediate exit from the loop can be achieved by a ------------ statement.
52. C keywords can be used as variable names. False
53. A # define is a compiler directive and not a statement. True
54. # define lines should end with a semicolon. False
55. stdio.h refers to standard l/o header file. True
56. stdio.h contains mathematical functions. False
57. Every C program must have at least one main ( ) function section. False
58. Every C program ends with an END word. False
59. A printf ( ) function generate only one line of output. False
60. The basic meaning of the C keywords can be changed. False
61. The underscore character is allowed in identifiers.True
62. C language has two types of constants viz., numeric and character. True
63. In C, commas are allowed in between digits of an integer. False
64. The number -71 is not valid in C. False
65. In c language, a character constant ‘x’ is not equivalent to the single character constant “x”. True
66. A double data type number uses 64 bits giving a precision of 14 digits. True
67. The # define statements may appear anywhere in the program. True
68. There should be a space between the pound sign (#) and the word define. False
69. #define statements must not end with a semicolon. True
70. The statement #define X = 5.5 is invalid. True
71. The statement # define N 5, M 25 is valid. False
72. # define N 25 is valid. True
73. x + = 3 is equivalent to x = x + 3. True
74. x = x/ (n+1) is equivalent to x / = n + 1. True
75. a (j + + ) = 25 is equivalent to a( j ) = 25. True
76. The assignment statement a = = b = c = 0; is not a valid c language. False
77. An assignment statement includes = = symbol. False
78. Char y = ‘a’ is a valid C statement. True
79. scanf ( ) function can be used to read values through keyboard. True
80. The scanf ( ) function can be used without variables list. True
81. In Scanf ( ) function, the control string represents the format of data being received. True
82. The function (float) n converts the value of n to type float. True
83. fabs (x) function returns the absolute value of x. True
84. floor (x) function rounded off the value of x , which is less than or equivalent to x. True
85. log(x) function returns the natural log of x. True
86. isalnum ( c ) checks whether c is an alphanumeric character or not. True
87. isprint ( c ) function checks whether c is a printable character or not. True
88. ispunct ( ) function checks whether c consists of a punctuation mark or not. True
89. isspace ( ) function checks c is a white space character or not. True
90. puchar (‘/n’) would move the cursor to the beginning of the next line. True
91. In C, each string is terminated by a ‘/0’ character. True
92. A string can be read using the format %s or %c. False
93. The printf variable list must be preceded by a “& ’’ symbol. False
94. “%c’’ code can be used to read/print a character. True
95. “%d’’ code can be used to read/print decimal integer. True
96. “%e’’ code can be used to read/print floating point values with exponent. Ans: True
97. “%f’’ code can be used to read/print floating point values without exponent. Ans: True 98. The
statement Scanf(“%d,%d’’, & d1, & d2);
Can be used to read two decimal integer values in C language. Ans:True
99. “%s” format can be used to read/print a string. Ans:True
100. “%u” format is used to read/print an unsigned decimal integer. Ans:True

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

2- Why is C known as a mother language?


C is known as a mother language because most of the compilers and JVMs are written
in C language. Most of the languages which are developed after C language has
borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core
concepts like arrays, functions, file handling which are used in these languages.

3- Why is C called a mid-level programming language?


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.

4- Who is the founder of C language?


Dennis Ritchie.

5- When was C language developed?


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

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

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

8- What is the difference between the local variable and global variable in C?
Following are the differences between a local variable and global variable:

Basis for
Local variable Global variable
comparison
A variable which is declared inside A variable which is declared outside
Declaration function or block is known as a local function or block is known as a
variable. global variable.
The scope of a variable is available within The scope of a variable is available
Scope
a function in which they are declared. throughout the program.
Variables can be accessed only by those
Any statement in the entire program
Access statements inside a function in which
can access variables.
they are declared.
Life of a variable is created when the
Life of a variable exists until the
Life function block is entered and destroyed
program is executing.
on its exit.
Variables are stored in a stack unless The compiler decides the storage
Storage
specified. location of a variable.
9- 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.
 The static variable is used as a common value which is shared by all the methods.
 The static variable is initialized only once in the memory heap to reduce the memory
usage.

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

11- 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 arguments Actual arguments and formal
Memory
are created in separate memory arguments are created in the same
location
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.
Example of call by value:
1. #include <stdio.h>
2. void change(int,int);
3. int main()
4. {
5. int a=10,b=20;
6. change(a,b); //calling a function by passing the values of variables.
7. printf(“Value of a is: %d”,a);
8. printf(“\n”);
9. printf(“Value of b is: %d”,b);
10. return 0;
11. }
12. void change(int x,int y)
13. {
14. x=13;
15. y=17;
16. }

Output:

Value of a is: 10
Value of b is: 20
Example of call by reference:

1. #include <stdio.h>
2. void change(int*,int*);
3. int main()
4. {
5. int a=10,b=20;
6. change(&a,&b); // calling a function by passing references of variables.
7. printf(“Value of a is: %d”,a);
8. printf(“\n”);
9. printf(“Value of b is: %d”,b);
10. return 0;
11. }
12. void change(int *x,int *y)
13. {
14. *x=13;
15. *y=17;
16. }

Output:

Value of a is: 13
Value of b is: 17
12- 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.

Recursive function comes in two phases:

1. Winding phase
2. Unwinding phase

Winding phase: When the recursive function calls itself, and this phase ends when the
condition is reached.

Unwinding phase: Unwinding phase starts when the condition is reached, and the
control returns to the original call.

Example of recursion

1. #include <stdio.h>
2. int calculate_fact(int);
3. int main()
4. {
5. int n=5,f;
6. f=calculate_fact(n); // calling a function
7. printf(“factorial of a number is %d”,f);
8. return 0;
9. }
10. int calculate_fact(int a)
11. {
12. if(a==1)
13. {
14. return 1;
15. }
16. else
17. return a*calculate_fact(a-1); //calling a function recursively.
18. }

Output:

factorial of a number is 120


13- 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];

Example of an array:

1. #include <stdio.h>
2. int main()
3. {
4. int arr[5]={1,2,3,4,5}; //an array consists of five integer values.
5. for(int i=0;i<5;i++)
6. {
7. printf(“%d “,arr[i]);
8. }
9. return 0;
10. }

Output:

12345
14- 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.

Example of pointer

1. #include <stdio.h>
2. int main()
3. {
4. int *p; //pointer of type integer.
5. int a=5;
6. p=&a;
7. printf(“Address value of ‘a’ variable is %u”,p);
8. return 0;
9. }

Output:

Address value of 'a' variable is 428781252


15- What is the usage of the pointer in C?

 Accessing array elements: Pointers are used in traversing through an array of integers
and strings. The string is an array of characters which is terminated by a null character
‘\0’.
 Dynamic memory allocation: Pointers are used in allocation and deallocation of
memory during the execution of a program.
 Call by Reference: The pointers are used to pass a reference of a variable to other
function.
 Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct
different data structures like tree, graph, linked list, etc.

16- 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.
17- 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.

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

Let’s see this through an example.

1. #include<stdio.h>
2. void main()
3. {
4. int *ptr = malloc(constant value); //allocating a memory space.
5. free(ptr); //ptr becomes a dangling pointer.
6. }

In the above example, initially memory is allocated to the pointer variable ptr, and then
the memory is deallocated from the pointer variable. Now, pointer variable, i.e., ptr
becomes a dangling pointer.

How to overcome the problem of a dangling pointer

The problem of a dangling pointer can be overcome by assigning a NULL value to the
dangling pointer. Let’s understand this through an example:

1. #include<stdio.h>
2. void main()
3. {
4. int *ptr = malloc(constant value); //allocating a memory space.
5. free(ptr); //ptr becomes a dangling pointer.
6. ptr=NULL; //Now, ptr is no longer a dangling pointer.
7. }
In the above example, after deallocating the memory from a pointer variable, ptr is
assigned to a NULL value. This means that ptr does not point to any memory location.
Therefore, it is no longer a dangling pointer.

19- What is pointer to pointer in C?


In case of a pointer to pointer concept, one pointer refers to the address of another
pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains
the address of a variable. The pointer to pointer contains the address of a first pointer.
Let’s understand this concept through an example:

1. #include <stdio.h>
2. int main()
3. {
4. int a=10;
5. int *ptr,**pptr; // *ptr is a pointer and **pptr is a double pointer.
6. ptr=&a;
7. pptr=&ptr;
8. printf(“value of a is:%d”,a);
9. printf(“\n”);
10. printf(“value of *ptr is : %d”,*ptr);
11. printf(“\n”);
12. printf(“value of **pptr is : %d”,**pptr);
13. return 0;
14. }

In the above example, pptr is a double pointer pointing to the address of the ptr
variable and ptr points to the address of ‘a’ variable.

20- What is static memory allocation?

 In case of static memory allocation, memory is allocated at compile time, and memory
can’t be increased while executing the program. It is used in the array.
 The lifetime of a variable in static memory is the lifetime of a program.
 The static memory is allocated using static keyword.
 The static memory is implemented using stacks or heap.
 The pointer is required to access the variable present in the static memory.
 The static memory is faster than dynamic memory.
 In static memory, more memory space is required to store the variable.

1. For example:
2. int a[10];
The above example creates an array of integer type, and the size of an array is fixed,
i.e., 10.

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

22- 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() function.
2. 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.

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

#1) What are the key features in the C programming language?


Answer: Features are as follows:
 Portability: It is a platform-independent language.
 Modularity: Possibility to break down large programs into small modules.
 Flexibility: The possibility of a programmer to control the language.
 Speed: C comes with support for system programming and hence it compiles and
executes with high speed when compared with other high-level languages.
 Extensibility: Possibility to add new features by the programmer.
Q #2) What are the basic data types associated with C?
Answer:
 Int – Represent the number (integer)
 Float – Number with a fraction part.
 Double – Double-precision floating-point value
 Char – Single character
 Void – Special purpose type without any value.
Q #3) What is the description for syntax errors?
Answer: The mistakes/errors that occur while creating a program are called syntax errors.
Misspelled commands or incorrect case commands, an incorrect number of parameters in
calling method /function, data type mismatches can be identified as common examples for
syntax errors.
Q #4) What is the process to create increment and decrement statement in C?
Answer: There are two possible methods to perform this task.
 Use increment (++) and decrement (-) operator.
Example When x=4, x++ returns 5 and x- returns 3.
 Use conventional + or – sign.
Example When x=4, use x+1 to get 5 and x-1 to get 3.
Q #5) What are reserved words with a programming language?
Answer: The words that are a part of the standard C language library are called reserved
words. Those reserved words have special meaning and it is not possible to use them for
any activity other than its intended functionality.
Example: void, return int.
Q #6) What is the explanation for the dangling pointer in C?
Answer: When there is a pointer pointing to a memory address of any variable, but after
some time the variable was deleted from the memory location while keeping the pointer
pointing to that location is known as a dangling pointer in C.
Q #7) Describe static function with its usage?
Answer: A function, which has a function definition prefixed with a static keyword is
defined as a static function. The static function should be called within the same source
code.
Q #8) What is the difference between abs() and fabs() functions?
Answer: Both functions are to retrieve absolute value. abs() is for integer values and
fabs() is for floating type numbers. Prototype for abs() is under the library file < stdlib.h >
and fabs() is under < math.h >.
Q #9) Describe Wild Pointers in C?
Answer: Uninitialized pointers in the C code are known as Wild Pointers. They point to
some arbitrary memory location and can cause bad program behavior or program crash.
Q #10) What is the difference between ++a and a++?
Answer: ‘++a” is called prefixed increment and the increment will happen first on a
variable. ‘a++’ is called postfix increment and the increment happens after the value of a
variable used for the operations.
Q #11) Describe the difference between = and == symbols in C programming?
Answer: ‘==’ is the comparison operator which is used to compare the value or
expression on the left-hand side with the value or expression on the right-hand side.
‘=’ is the assignment operator which is used to assign the value of the right-hand side to
the variable on the left-hand side.

Q #12) What is the explanation for prototype function in C?


Answer: Prototype function is a declaration of a function with the following information to
the compiler.
 Name of the function.
 The return type of the function.
 Parameters list of the function.

In this example Name of the function is Sum, the return type is the integer data type and it
accepts two integer parameters.

Q #13) What is the explanation for the cyclic nature of data types in C?
Answer: Some of the data types in C have special characteristic nature when a developer
assigns value beyond the range of the data type. There will be no compiler error and the
value changes according to a cyclic order. This is called cyclic nature. Char, int, long int
data types have this property. Further float, double and long double data types do not
have this property.
Q #14) Describe the header file and its usage in C programming?
Answer: The file containing the definitions and prototypes of the functions being used in
the program are called a header file. It is also known as a library file.
Example: The header file contains commands like printf and scanf is from the stdio.h
library file.
Q #15) There is a practice in coding to keep some code blocks in comment symbols
than delete it when debugging. How this affects when debugging?
Answer: This concept is called commenting out and this is the way to isolate some part of
the code which scans possible reason for the error. Also, this concept helps to save time
because if the code is not the reason for the issue it can simply be removed from
comment.
Q #16) What are the general description for loop statements and available loop
types in C?
Answer: A statement that allows the execution of statements or groups of statements in a
repeated way is defined as a loop.
The following diagram explains a general form of a loop.

There are 4 types of loop statements in C.


 While loop
 For Loop
 Do…While Loop
 Nested Loop
Q #17) What is a nested loop?
Answer: A loop that runs within another loop is referred to as a nested loop. The first
loop is called the Outer Loop and the inside loop is called the Inner Loop. The inner loop
executes the number of times defined in an outer loop.
Q #18) What is the general form of function in C?
Answer: The function definition in C contains four main sections.
return_type function_name( parameter list )
{
body of the function
}
 Return Type: Data type of the return value of the function.
 Function Name: The name of the function and it is important to have a meaningful
name that describes the activity of the function.
 Parameters: The input values for the function that are used to perform the required
action.
 Function Body: Collection of statements that performs the required action.
Q #19) What is a pointer on a pointer in C programming language?
Answer: A pointer variable that contains the address of another pointer variable is called
pointer on a pointer. This concept de-refers twice to point to the data held by a pointer
variable.

In this example **y returns the value of the variable a.


Q #20) What are the valid places to have keyword “Break”?
Answer: The purpose of the Break keyword is to bring the control out of the code block
which is executing. It can appear only in looping or switch statements.
Q #21) What is the behavioral difference when the header file is included in double-
quotes (“”) and angular braces (<>)?
Answer: When the Header file is included within double quotes (“ ”), compiler search first
in the working directory for the particular header file. If not found, then it searches the file
in the include path. But when the Header file is included within angular braces (<>), the
compiler only searches in the working directory for the particular header file.
Q #22) What is a sequential access file?
Answer: General programs store data into files and retrieve existing data from files. With
the sequential access file, such data are saved in a sequential pattern. When retrieving
data from such files each data is read one by one until the required information is found.
Q #23) What is the method to save data in a stack data structure type?
Answer: Data is stored in the Stack data structure type using the First In Last Out
(FILO) mechanism. Only top of the stack is accessible at a given instance. Storing
mechanism is referred as a PUSH and retrieve is referred to as a POP.
Q #24) What is the significance of C program algorithms?
Answer: The algorithm is created first and it contains step by step guidelines on how the
solution should be. Also, it contains the steps to consider and the required
calculations/operations within the program.
Q #25) What is the correct code to have the following output in C using nested for
loop?

Answer:
#include <stdio.h>

int main () {

int a;
int b;
/* for loop execution */
for( a = 1; a < 6; a++ )
{
/* for loop execution */
for ( b = 1; b <= a; b++ )
{
printf("%d",b);
}
printf("\n");
}

return 0;
}
Q #26) Explain the use of function toupper() with an example code?
Answer: Toupper() function is used to convert the value to uppercase when it used with
characters.
Code:
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;

c = 'a';
printf("%c -> %c", c, toupper(c));

c = 'A';
printf("\n%c -> %c", c, toupper(c));

c = '9';
printf("\n%c -> %c", c, toupper(c));
return 0;
}
Result:

Q #27) What is the code in a while loop that returns the output of the given code?
#include <stdio.h>

int main () {

int a;

/* for loop execution */


for( a = 1; a <= 100; a++ )
{
printf("%d\n",a * a);
}

return 0;
}

Answer:
#include <stdio.h>

int main () {

int a;

while (a<=100)
{
printf ("%d\n", a * a);
a++;
}
return 0;
}

Q #28) Select the incorrect operator form in the following list(== , <> , >= , <=) and
what is the reason for the answer?
Answer: Incorrect operator is ‘<>’. This format is correct when writing conditional
statements, but it is not the correct operation to indicate not equal in C programming. It
gives a compilation error as follows.
Code:
#include <stdio.h>
int main () {

if ( 5 <> 10 )
printf( "test for <>" );
return 0;
}

Error:

Q #29) Is it possible to use curly brackets ({}) to enclose a single line code in C
program?
Answer: Yes, it works without any error. Some programmers like to use this to organize
the code. But the main purpose of curly brackets is to group several lines of codes.
Q #30) Describe the modifier in C?
Answer: Modifier is a prefix to the basic data type which is used to indicate the
modification for storage space allocation to a variable.
Example– In a 32-bit processor, storage space for the int data type is 4.When we use it
with modifier the storage space change as follows:
 Long int: Storage space is 8 bit
 Short int: Storage space is 2 bit
Q #31) What are the modifiers available in C programming language?
Answer: There are 5 modifiers available in the C programming language as follows:
 Short
 Long
 Signed
 Unsigned
 long long
Q #32) What is the process to generate random numbers in C programming
language?
Answer: The command rand() is available to use for this purpose. The function returns an
integer number beginning from zero(0). The following sample code demonstrates the use
of rand().
Code:
#include <stdio.h>
#include <stdlib.h>

int main ()
{
int a;
int b;

for(a=1; a<11; a++)


{
b = rand();
printf( "%d\n", b );
}
return 0;
}

Output:

Q #33) Describe the newline escape sequence with a sample program?


Answer: The Newline escape sequence is represented by \n. This indicates the point that
the new line starts to the compiler and the output is created accordingly. The following
sample program demonstrates the use of the newline escape sequence.
Code:
/*
* C Program to print string
*/
#include <stdio.h>
#include <string.h>
int main(){
printf("String 01 ");
printf("String 02 ");
printf("String 03 \n");

printf("String 01 \n");
printf("String 02 \n");
return 0;
}
Output:

Q #34) Is that possible to store 32768 in an int data type variable?


Answer: Int data type is only capable of storing values between – 32768 to 32767. To
store 32768 a modifier needs to used with the int data type. Long Int can use and also if
there are no negative values, unsigned int is also possible to use.
Q #35) Is there any possibility to create a customized header file with C
programming language?
Answer: Yes, it is possible and easy to create a new header file. Create a file with
function prototypes that are used inside the program. Include the file in the ‘#include’
section from its name.
Q #36) Describe dynamic data structure in C programming language?
Answer: Dynamic data structure is more efficient to memory. The memory access occurs
as needed by the program.
Q #37) Is that possible to add pointers to each other?
Answer: There is no possibility to add pointers together. Since pointer contains address
details there is no way to retrieve the value from this operation.
Q #38) What is indirection?
Answer: If you have defined a pointer to a variable or any memory object, there is no
direct reference to the value of the variable. This is called the indirect reference. But when
we declare a variable, it has a direct reference to the value.
Q #39) What are the ways to a null pointer that can be used in the C programming
language?
Answer: Null pointers are possible to use in three ways.
 As an error value.
 As a sentinel value.
 To terminate indirection in the recursive data structure.
Q #40) What is the explanation for modular programming?
Answer: The process of dividing the main program into executable subsection is called
module programming. This concept promotes reusability.
 What is a pointer on pointer?
It’s a pointer variable which can hold the address of another pointer variable. It de-
refers twice to point to the data held by the designated pointer variable.
Eg: int x = 5, *p=&x, **q=&p;
Therefore ‘x’ can be accessed by **q.

 Distinguish between malloc() & calloc() memory allocation.


Both allocates memory from heap area/dynamic memory. By default calloc fills the
allocated memory with 0’s.

 What is keyword auto for?


By default every local variable of the function is automatic (auto). In the below function
both the variables ‘i’ and ‘j’ are automatic variables.
void f() {
int i;
auto int j;
}
NOTE − A global variable can’t be an automatic variable.

 What are the valid places for the keyword break to appear.
Break can appear only with in the looping control and switch statement. The purpose
of the break is to bring the control out from the said blocks.

 Explain the syntax for for loop.


 for(expression-1;expression-2;expression-3) {
 //set of statements
}
When control reaches for expression-1 is executed first. Then following expression-2,
and if expression-2 evaluates to non-zero ‘set of statements’ and expression-3 is
executed, follows expression-2.

 What is difference between including the header file with-in angular braces < > and
double quotes “ “
If a header file is included with in < > then the compiler searches for the particular
header file only with in the built in include path. If a header file is included with in “ “,
then the compiler searches for the particular header file first in the current working
directory, if not found then in the built in include path.

 How a negative integer is stored.


Get the two’s compliment of the same positive integer. Eg: 1011 (-5)
Step-1 − One’s compliment of 5 : 1010
Step-2 − Add 1 to above, giving 1011, which is -5

 What is a static variable?


A static local variables retains its value between the function call and the default value
is 0. The following function will print 1 2 3 if called thrice.
void f() {
static int i;
++i;
printf(“%d “,i);
}
If a global variable is static then its visibility is limited to the same source code.

 What is a NULL pointer?


A pointer pointing to nothing is called so. Eg: char *p=NULL;

 What is the purpose of extern storage specifier?


Used to resolve the scope of global symbol.
Eg:
main() {
extern int i;
Printf(“%d”,i);
}

int i = 20;

 Explain the purpose of the function sprintf().


Prints the formatted output onto the character array.

 What is the meaning of base address of the array?


The starting address of the array is called as the base address of the array.

 When should we use the register storage specifier?


If a variable is used most frequently then it should be declared using register storage
specifier, then possibly the compiler gives CPU register for its storage to speed up the
look up of the variable.

 S++ or S = S+1, which can be recommended to increment the value by 1 and why?
S++, as it is single machine instruction (INC) internally.

 What is a dangling pointer?


A pointer initially holding valid address, but later the held address is released or freed.
Then such a pointer is called as dangling pointer.

 What is the purpose of the keyword typedef?


It is used to alias the existing type. Also used to simplify the complex declaration of
the type.

 What is lvalue and rvalue?


The expression appearing on right side of the assignment operator is called as rvalue.
Rvalue is assigned to lvalue, which appears on left side of the assignment operator.
The lvalue should designate to a variable not a constant.

 What is the difference between actual and formal parameters?


The parameters sent to the function at calling end are called as actual parameters
while at the receiving of the function definition called as formal parameters.

 Can a program be compiled without main() function?


Yes, it can be but cannot be executed, as the execution requires main() function
definition.

 What is the advantage of declaring void pointers?


When we do not know what type of the memory address the pointer variable is going
to hold, then we declare a void pointer for such.

 Where an automatic variable is stored?


Every local variable by default being an auto variable is stored in stack memory.

 What is a nested structure?


A structure containing an element of another structure as its member is referred so.

 What is the difference between variable declaration and variable definition?


Declaration associates type to the variable whereas definition gives the value to the
variable.

 What is a self-referential structure?


A structure containing the same structure pointer variable as its element is called as
self-referential structure.

 Does a built-in header file contains built-in function definition?


No, the header file only declares function. The definition is in library which is linked by
the linker.
 Explain modular programming.
Dividing the program in to sub programs (modules/function) to achieve the given task
is modular approach. More generic functions definition gives the ability to re-use the
functions, such as built-in library functions.

 What is a token?
A C program consists of various tokens and a token is either a keyword, an identifier,
a constant, a string literal, or a symbol.

 What is a preprocessor?
Preprocessor is a directive to the compiler to perform certain things before the actual
compilation process begins.

 Explain the use of %i format specifier w.r.t scanf().


Can be used to input integer in all the supported format.

 How can you print a \ (backslash) using any of the printf() family of functions.
Escape it using \ (backslash).

 Does a break is required by default case in switch statement?


Yes, if it is not appearing as the last case and if we do not want the control to flow to
the following case after default if any.

 When to user -> (arrow) operator.


If the structure/union variable is a pointer variable, to access structure/union elements
the arrow operator is used.

 What are bit fields?


We can create integer structure members of differing size apart from non-standard
size using bit fields. Such structure size is automatically adjusted with the multiple of
integer size of the machine.

 What are command line arguments?


The arguments which we pass to the main() function while executing the program are
called as command line arguments. The parameters are always strings held in the
second argument (below in args) of the function which is array of character pointers.
First argument represents the count of arguments (below in count) and updated
automatically by operating system.
main( int count, char *args[]) {
}
 What are the different ways of passing parameters to the functions? Which to use
when?
 Call by value − We send only values to the function as parameters. We choose
this if we do not want the actual parameters to be modified with formal
parameters but just used.
 Call by reference − We send address of the actual parameters instead of
values. We choose this if we do want the actual parameters to be modified with
formal parameters.

 What is the purpose of built-in stricmp() function.


It compares two strings by ignoring the case.

 Describe the file opening mode “w+”.


Opens a file both for reading and writing. If a file is not existing it creates one, else if
the file is existing it will be over written.

 Where the address of operator (&) cannot be used?


It cannot be used on constants.
It cannot be used on variable which are declared using register storage class.

 Is FILE a built-in data type?


No, it is a structure defined in stdio.h.
 What is reminder for 5.0 % 2?
Error, It is invalid that either of the operands for the modulus operator (%) is a real
number.

 How many operators are there under the category of ternary operators?
There is only one operator and is conditional operator (? : ).

 Which key word is used to perform unconditional branching?


goto

 What is a pointer to a function? Give the general syntax for the same.
A pointer holding the reference of the function is called pointer to a function. In general
it is declared as follows.
T (*fun_ptr) (T1,T2…); Where T is any date type.
Once fun_ptr refers a function the same can be invoked using the pointer as follows.
fun_ptr();
[Or]
(*fun_ptr)();

 Explain the use of comma operator (,).


Comma operator can be used to separate two or more expressions.
Eg: printf(“hi”) , printf(“Hello”);

 What is a NULL statement?


A null statement is no executable statements such as ; (semicolon).
Eg: int count = 0;
while( ++count<=10 ) ;
Above does nothing 10 times.

 What is a static function?


A function’s definition prefixed with static keyword is called as a static function. You
would make a function static if it should be called only within the same source code.

 Which compiler switch to be used for compiling the programs using math library with
gcc compiler?
Opiton –lm to be used as > gcc –lm <file.c>

 Which operator is used to continue the definition of macro in the next line?
Backward slash (\) is used.
E.g. #define MESSAGE "Hi, \

Welcome to C"
 Which operator is used to receive the variable number of arguments for a function?
Ellipses (…) is used for the same. A general function definition looks as follows
void f(int k,…) {
}

 What is the problem with the following coding snippet?


 char *s1 = "hello",*s2 = "welcome";

strcat(s1,s2);
s1 points to a string constant and cannot be altered.

 Which built-in library function can be used to re-size the allocated dynamic memory?
realloc().

 Define an array.
Array is collection of similar data items under a common name.

 What are enumerations?


Enumerations are list of integer constants with name. Enumerators are defined with
the keyword enum.

 Which built-in function can be used to move the file pointer internally?
fseek()

 What is a variable?
A variable is the name storage.

 Who designed C programming language?


Dennis M Ritchie.

 C is successor of which programming language?


B

 What is the full form of ANSI?


American National Standards Institute.

 Which operator can be used to determine the size of a data type or variable?
sizeof

 Can we assign a float variable to a long integer variable?


Yes, with loss of fractional part.

 Is 068 a valid octal number?


No, it contains invalid octal digits.

 What it the return value of a relational operator if it returns any?


Return a value 1 if the relation between the expressions is true, else 0.

 How does bitwise operator XOR works.


If both the corresponding bits are same it gives 0 else 1.

 What is an infinite loop?


A loop executing repeatedly as the loop-expression always evaluates to true such as
while(0 == 0) {
}
 Can variables belonging to different scope have same name? If so show an example.
Variables belonging to different scope can have same name as in the following code
snippet.
int var;

void f() {
int var;
}

main() {
int var;
}

 What is the default value of local and global variables?


Local variables get garbage value and global variables get a value 0 by default.

 Can a pointer access the array?


Pointer by holding array’s base address can access the array.

 What are valid operations on pointers?


The only two permitted operations on pointers are

 Comparision ii) Addition/Substraction (excluding void pointers)

 What is a string length?


It is the count of character excluding the ‘\0’ character.

 What is the built-in function to append one string to another?


strcat() form the header string.h

 Which operator can be used to access union elements if union variable is a pointer
variable?
Arrow (->) operator.

 Explain about ‘stdin’.


stdin in a pointer variable which is by default opened for standard input device.

 Name a function which can be used to close the file stream.


fclose().

 What is the purpose of #undef preprocessor?


It be used to undefine an existing macro definition.
 Define a structure.
A structure can be defined of collection of heterogeneous data items.

 Name the predefined macro which be used to determine whether your compiler is ANSI
standard or not?
__STDC__

 What is typecasting?
Typecasting is a way to convert a variable/constant from one type to another type.

 What is recursion?
Function calling itself is called as recursion.

 Which function can be used to release the dynamic allocated memory?


free().

 What is the first string in the argument vector w.r.t command line arguments?
Program name.

 How can we determine whether a file is successfully opened or not using fopen()
function?
On failure fopen() returns NULL, otherwise opened successfully.

 What is the output file generated by the linker.


Linker generates the executable file.

 What is the maximum length of an identifier?


Ideally it is 32 characters and also implementation dependent.

 What is the default function call method?


By default the functions are called by value.

 Functions must and should be declared. Comment on this.


Function declaration is optional if the same is invoked after its definition.

 When the macros gets expanded?


At the time of preprocessing.

 Can a function return multiple values to the caller using return reserved word?
No, only one value can be returned to the caller.
 What is a constant pointer?
A pointer which is not allowed to be altered to hold another address after it is holding
one.

 To make pointer generic for which date type it need to be declared?


Void

 Can the structure variable be initialized as soon as it is declared?


Yes, w.r.t the order of structure elements only.

 Is there a way to compare two structure variables?


There is no such. We need to compare element by element of the structure variables.

 Which built-in library function can be used to match a patter from the string?
Strstr()

 What is difference between far and near pointers?


In first place they are non-standard keywords. A near pointer can access only 2^15
memory space and far pointer can access 2^32 memory space. Both the keywords
are implementation specific and are non-standard.

 Can we nest comments in a C code?


No, we cannot.

 Which control loop is recommended if you have to execute set of statements for fixed
number of times?
for – Loop.

 What is a constant?
A value which cannot be modified is called so. Such variables are qualified with the
keyword const.

 Can we use just the tag name of structures to declare the variables for the same?
No, we need to use both the keyword ‘struct’ and the tag name.

 Can the main() function left empty?


Yes, possibly the program doing nothing.

 Can one function call another?


Yes, any user defined function can call any function.

You might also like