The document contains a comprehensive list of viva questions and answers related to computer programming, specifically focusing on the C programming language. Key topics include definitions of C language, algorithms, flowcharts, data types, operators, and various programming concepts such as functions, arrays, and pointers. It also covers syntax for conditional statements, storage classes, and string manipulation functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views12 pages
C Programming Viva Questions
The document contains a comprehensive list of viva questions and answers related to computer programming, specifically focusing on the C programming language. Key topics include definitions of C language, algorithms, flowcharts, data types, operators, and various programming concepts such as functions, arrays, and pointers. It also covers syntax for conditional statements, storage classes, and string manipulation functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
Computer Programming Viva Questions
y
COMPUTER PROGRAMMING VIVA QUESTIONS
What is C language?
Ans:
2
3)
D}
5)
6)
n
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.
Tt has since spread to many other operating systems, and is one of the most widely used
programming languages.
What is an algorithm?
Aus: An algorithm is a step-by-step method of performing any task.
What is a flow chart?
Ams: A flowchart is a type of diagram that represents an algorithm or process, showing
the steps as boxes of various kinds, and their order by connecting these with arrows.
What is a C Preprocessor?
Ams: C Preprocessor is a program that processes our source program before it is passed to
the compiler.
‘What is the use of header files as used in C programming?
Ans: Header files are used to have declarations. [Lis simple to include a single header file
than writing allthe needed functions prototypes.
‘What is the Structure of a C Program?
Ans: Documentation Section, Linking Section, Definition Section, Global declaration
Section, main function, subprogram section.
Explain some Header Files?
Ams:
Header 5
sno | fr Description
This is standard input/output header file in
1 |stdioh | which Input/Output
functions are declared
2 _[conio.h _| This is console input/output header file
All string related functions are defined in this
3 [strings | header tile
‘This header file contains general functions
used in C programsComputer Programming Viva Questions
All maths related functions are defined in this
3 header file
math.h
8) What is the use of main( function?
‘Ans: main() is the starting point of program execution.
9) What are the types of constants in c?
Ans: C constants can ba divided into two categories:
1) Primary constants (Numerical)
2) Secondary constants (Character)
10) What is a Compiler?
Ans: A compiler is a computer program (or set of programs) that transforms source
code written in a programming language (the source Ianguage) into another computer
language (the target language, often having a binary form known as object code).
11) What is a Translator?
Ans: Atranslator is a computer program that translates a program written in a
given programming language into a functionally equivalent program in a different
language.
12) What is a Interpreter?
Ans: An Interpreter is acompuler program that directly executes, i.e. performs,
instructions written in a programming or scripting language, without previously batch-
compiling them into machine language.
13) What is a Token in C?
Ans: A Token is the hasic building block of aC. (or) the hasic element recognized by
the compiler is the "token."
‘C Tokens are:
Key Words, Identifier, Constants, String — literal, Operator, Punctuators
14) What are Printf() and scanf() Functions :
Ans: printf{) and scanf() functions are inbuilt library functions in C which are available
in which are available in * stdio.h" header file.
+ printf() function is used to print the “character, string, float, integer, octal and
hexadecimal values” onto the output screen,
+ scanf() function is used to read character, string, numeric data from keyboard,17) What is enum Data Type?
Ans:
Enumeration data type consists of named inieger constants as a list.
It start with 0 (zero) by Gefault and value is incremented by 1 for the sequential
identifiers in the list.
Syntax:
enum identifier { enumerator-lst };
18) What is a Void Data Type?
Ans: Void is an empty data type thet has no value,
19) What is a comment in C?
Ans: Comments are like helping text in your C program and they are ignored by the
compiler. We can write in between /* and */ or // (Line Comments)
20) What is an Identifler In C?
‘Ans: A C identifier is a name used to identify a variable, function, or any other user-
defined item. An identifier starts with a letie: A to Z or ato zor an underscore _followedl
by zero or more letters, underscores, and digits (0 to 8). C does not allow punctuation
characters such as @, $, and % within identifiers. C is a case sensitive programming
language.
21) What is a Key word in C?
Ans: Keywords are reserved words in C and Keywords are may not be used as constant
or variable or any other identifier names.
22) How many Keywords are there in C and List out the Keywords?
Ans : There are 33 reserved keywords are there in C, They are:
auto else long switch
break enum register typedef
case exter return union
aur float short unsigned,
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double23) Define a Variable?
‘Ans: A variable is nothing but a name given to a storage area that our programs can
manipulate, Each variable in C has a specific type, which determines the size and layout
of the varieble's memory.
Syntax for variable Declaration:
DataType VariableList;
int ig;
cabr ¢, ch;
24) What are the steps to develop a C Program?
Ans:
+ Specifying the problem statement
+ Designing an algorithm
+ Coding
+ Debugging
+ Testing and Validating
+ Documentation and Maintenance
25) What is the process of debugging or compilation for C Programs?
‘Ans: To check the errors in a program is called debugging or compilation. This process
done by 3 stage:
1) Checking Syntactic Exrors: These ezzors occur due to the usage of wrong syntax
for the slalements. (Shor! cut Key : ALT+F9)
2) Checking Run time Errors/ Linkage Errors: These Errors are determined at the
execution time of the program (EX: Divide a number by Zero, finding logarithm
of negative number, finding square root of negative number ,ete.)
3) Checking Linker Errors: These errors are occurred due to the linking of header
file to the current program (Short cut Key : CTRL+F9)
4) Checking Logical Errors: These Errors occur due to incorrect usage of the
instruction in the program. Logical Errors are determined by analyzing the outputs
for different possible inputs that can be applied to the program.
26) List some Syntactic Errors or Syntax Errors?
Ans: 1} Missing semicolon(Statement. Missing ;)
2) Undeclared a variable name or Undefined symbol (Then check variable declaration
synlax and check for header file for some keywords)
3) *)' expected (Then check the no of parenthesis opened and closed)
4) legal string constant ( check for the last double quote in a string)
5) printf and scanf arguments should be placed in ( }
6) Compound statement missing (Check for the no of { and } are opened and closed)
7) Proto type missing ertor (Check for Function declaration statement)
8) Forgetting to put &,”, andl comma operator in specific places.35) What are Increment / Decrement Operators?
Ams: Increment operators are used to increase the value of the variable by one and
ecrement operators are used to decrease the value of the varicble by one in C programs
(Like ++, ~)
36) What are Special Operators?
Ams: &(Adaress Operator), * (Pointer Operator), and Sizeof()
37) What is sizeof operator?
Ans: It retumns the number of bytes the operand occupies.
38) What is pre-increment or post-increment?
Ans: ++n (pre increment) increments n before ils value is used in an assignment
‘operation or any expression containing it. n4+ (post increment) does increment after the
value of n is used.
39) What is type casting?
Ans: Converting a variable of one type to another type.
40) What are the Format Specifies or Type Specifies or Conversion Specifiers?
Ans: %d (Integer), %f (Float), %c (Character), %1 (Long Integer), %s (Strings), %u
(Address with decimal value), %p (Addzess with Hexa Decimal Value in Small Letters),
Sox ((Address with Hexa Decimal Value in Capital Letters)
41) What is a Statement in C?
‘Ans: A statement is a block of code that does something.
42) Different Types of Statements?
Ans: Null Statement, Expression Statement, Compound Statement, Retum Statement,
Conditional Statements, Iterative or Looping Statements, Unconditional Statements
43) Define Null Statement?
Ans: A “null statement" is a statement containing only a semicolon;
44) Define Expression Statement?
Ans: When an expression statement is executed, the expression is evaluated according to
the rules outlined in Expressions and Assignments.
45) Define Compound Statement?
‘Ans: A compound statement (also called a "block") typically appears as the body of
another statement which is in between { and }46) Define Return Statement?
Ans: The return statement terminates the execution of a function and returns control to
the calling function, A return statement can also return a value to the calling function.
47) Define Conditional Statements and give the list of them?
Ans: Conditional Statements which allows to perform actions depending upon some
conditions provided by the programmer. The Different types of conditional statements
are:
1) If Statement
2) If else statement
3) Nested- if else statement
4) Switch Statement
48) Write the Syntax for IF Statement?
Ams: if ( )
49) Write the Syntax for IF- ELSE Statement?
Ams: if ( )
else
«statement 2>
50) Write the Syntax for NESTED- IF - ELSE Statement?
Ans: if ( )
{
if()
{
t
else
{
t
}
else
‘
51) Write the Syntax for Switch Case Statement?
‘Ans: switch ( )
( }59) Define Break Statement, Write syntax for Break statement?
Ans: The breakstaiement terminates the execution ofthe nearest
enclosing do, for, switch, or while statement, in which it appears. Control passes to the
statement that follows the terminated statement.
Syntax:
break;
60) Define Continue Statement, Write syntax for Continue statement?
‘Ans: The continue statement passes control to the next iteration of the nearest
enclosing do, for, or while statement in which it appears
Syntax:
continue;
61) Define Type Qualifiers, and list them?
Ans: The keywords which are used to modify the properties of a variable are called type
quslifiers. There are two types of qualifiers available in C language. They are,1) const 2)
volatile
62) Define const Keyword with Syntax?
Ans: Constants are also like normal variables. They refer to fixed values, They are also
called as literals.
Syntax:
const data type variable name; (or) const data type *variable name;
63) Define volatile Keyword with Syntax?
Ans: When a variable is defined as volatile, the program may nol change the value of the
variable explicitly.
Syntax:
volatile daia_type variable_name; (or) volatile deta_type *variable_neme;
64) What is a Macro?
Ans: Macros are the identifiers that represent statements or expressions. To associate
‘meaningful identifiers with consiants, keywords, and statements or expressions,
65) What Is the difference between #include< > and include“ "?
Ans:
+ fincludec
Specifically used for built in header files.
+ include “”
Specifically used for used for user defined/ereated n header file,66) Define Storage class with Syntax?
Ams: Storage class specifiers in C language tells the compiler where to store a variable,
how to store the variable, what is the initial value of the variable and life time of the
variable
Syntax: storage specifier data type variable name
67) What are Different Storage Classes, Explain in brief?
Ans: There are 4 storage class specifiers available in C language. They are,
1) Auto
2) Extem
3) Static
4) Register
Initial /
Storage | Storage '
S.No. | Soecitier | place | fault | Scope | Life
value
1 r CPU Garbage local ‘Within the function
aula Memory [value °°" Joly.
Till the end of the
main
cPU program. Variable
2 extern | memory | 27° Global | cetinition might be
anywhere in the C
program
Retains the value of
3 [static [CPU Ver focat |? a
memory between different
function calls.
4 register | Resister | Garbage Tig.) | within the function
memory _| value
68) Define Array?
Ans: C Array is a collection of variables belongings to the same data type.
oR
An Array is a collection of Homogeneous or similar data type elements having unique
values, and stored ata different locations. You can store group of data of seme data type
in an array.
69) Types of an Array?
Ams: There are 2 types of C arrays. They are,int arr{2][2];
arr [0] JL.
arr [1][0]
arr (1] [1] = 4;
73) How we can read or print the array elements?
Ans: To read or print the array elements we need to use FOR Statement
74) Define a String?
Ans: C Strings are nothing but array of characters ended with null character (‘10’).
Strings are always enclosed by double quotes. Whereas, character is enclosed by single
quotes in C.
‘Examp!
char string[20] = { ‘H’, ‘e” , ‘I, ‘I’, ‘o' , 10"); (or)
char string[20] = “Hello”; (or)
char string []
= “Hello”;
75) Header used for String Functions?
Ans: finclude
76) List String Handling Functions or String Manipulation Functions?
Ans: streat(), stmoat(), stromp(), stmemp(), strempi(), strcpy(), stmopy(), strlen(),
strchr(), strrchr(), strstr(),strrsir(), strrev()
Function | Description Syntax
Name
strcat() Concatenates str? at the end of stri. Strcat(strl, str2);
simcal(} ‘appends a portion of siting to another | Streai(strl sir2.n); (First ny
siring characters of str. are
appends to str1)
siromp0) Returns 0 if str is same as str2, Returns | Stromp(str1,str2);
<0 ifssirl < str2. Returns >0 if str1 > str?
stomp | Compares some portion of a string in | Strncmp(sir1,str2,n);
another string
strompi() | Same as strompQ function. But, this | Strempi(strl,str2);
function negotiates case, “A” and “a” are
treated as same,
stropy0) Copies str2 into sir Stropy(strl si);
strmepy) copies given number of characters of one | Sirepy(sirl,sir2,n);
string to another
strlen) gives the length of string. Sirlen(sir);
strohr() Retums pointer to first ocourrence of char | Sitrohri(str, ’charcater’);in sitt
strrohr() Tast occurrence of given character in a | Strrohr(stz,’chercater’);
string is found
strstr) Relums pointer to first occurrence of sir2 | Strsir(str1,str2);
in str
strstr) Relums pointer lo last occurrence of sir2 | Sursir(stel sir2};
in str
SirrevO) reverses the given string Sirsie(strD);
77) What is the difference between strings and arrays?
Ans: String is a sequence of characters ending with NULL .it can be treated as a one
dimensional array of characters terminated by a NULL character.
78) Define Pointer with Syntax and example?
Ams: C Pointer is @ variable that storesfpoints the address of another variable. C Pointer is
used to allocate memory dynamicelly i.e. at run time,
Syntax: data_type *var_name;
Example : int +p; char *p;
79) What are the uses of Pointers?
Aus: Pointer is used in the following cases
+ Itis used to access array elements.
+ Itis used for dynamic memory allocation.
+ Itis used in Call by reference.
+ Itis used in data structures like trees, graph, linked list etc.
80) What is the invalid pointer Arithmetic?
Ans:
+ adding multiplying and dividing two pointers.
+ Shifting or masking pointer,
+ Addition of float or double to pointer
+ Assignment of a pointer of one type to a pointer of another type
81) What is a pointer value and address?
Ans: A pointer value is a data object that refers to a memory location. Each memory
location is numbered in the memory. 'The number altached to 2 memory location is called
the address of the location.
82) How are Pointer Variables initialized?
Ans: Pointer variable are initialized in two ways:
+ Static memory allocation+ Galloc is same as malloc but it initialize 0 value.callos () for allocating multiple
blocks of memory.
Syntax: *ptr-variable=(type-casting*)calloc(n,sizeof{DataType))
Example: *plr=(int*)calloc(5,sizeoftin'));
89) What Is the purpose of reallac?
Ans: It incteases or decreases the size of dynamically allocated array. The function
realloc (plr,n) uses two arguments. The first argument pir is a pointer to a block of
memory for which the size is to be altered. The second argument specifies the new size.
‘The size may be increased or decreased. If sufficient space is not available to the old
region the function may create a new region.
90) What is an Argument?
Ams: An argument is an entity used to pass data from the calling to a called function,
91) What are Buill-in-Functions/ Pre Defined Functions / Library Functions?
‘Ams: The functions that are predefined and supplied along with the compiler are known
as built in functions. They are also known as library functions.
92) What are the uses of Functions?
Ams:
+ C functions are used to avoid rewriting same logic/code again and again in a program.
+ There is no limit in calling C functions to make use of same functionality wherever
required.
+ We can call functions any number of times in a program and from any place in a
program.
+ Alarge C program can easily be tracked when it is divided into functions.
+ The core concept of C functions are, re-usability, dividing a big task into small picces
to achieve the functionality and to improve understandability of very large C
programs.
93) Define Function Declaration, Function Call and Function Definition with Syntaxes:
Ans:
+ Function declaration or prototype - ‘This informs compiler about the function
name, function parameters and return value’s data type.
+ Function call - This cells the actual function
+ Function definition ~ Tais contains all the statements to be executed,
C function
Sano | aspects syntax
1 _| fiametion retum_type function name ( arguments list )
definition { Body of function; }
2 _ | function catt function_name ( arguments list };funetion . ;
3 | dectaration retum_type function_name ( argument list );
94) Define Call by Value?
Ans: In call by value method, the value of the variable is passed to the function as
parameter. The velue of the actual parameter can not be modified by formal parameter.
Different Memory is allocated for both actual and formal parameters.
+ Achual parameter ~ This is the argument which is used in function call.
+ Formal parameter - This is the argument which is used in function definition
95) Define Call by Reference?
‘Ans: In call by reference method, the address of the variable is passed to the function as
parameter. The value of the actual parameter can be modified by formal parameter. Same
‘memory is used for both ac:ual and formal parameters since only address is used by both
parameters,
96) Explain the Categories of Functions?
Ans:
S.no |[ C function syntax
with arguments and || it! function ( int ); j/ function declaration
to taitn function ( a ); 1 function. call
retum values int function inta) —_// function definition
{statements; return a;}
with arguments and || ¥!4 function (int); #f function declaration
2 [rittout function( a ); Hf function call
return values void function int a) // function definition
{statements;}
without arguments || “#4 function(); if function declaration
3 jfand sataout | function; 4 function call
retum values void function() # function definition
{statements;}
without arguments | it function ( ); }{ fanction declaration
4 lana " with | fnction ( ); Hf function call
return values int function( ) # function definition
{statements; return a;}
97) List some MATHLH Functions?
Ans
S.no [Function Description
1 fabs) [This function returns the absolute value of an integer. The