Programming in C Viva
Programming in C Viva
Programming in C Viva
1. What is the difference between reading strings using scanf and gets?
Scanf cannot read strings with multiple words whereas gets can read strings with multiple words
2. What are the String-Handling functions available in C?
gets, puts, strcat, strcmp, strcpy and strlen.
3. What are the types of functions?
C functions are divided into two categories user-defined function and built-in functions
4. What is a function?
Function is a self contained block of statement which is used to perform certain task
5. Which are called built-in functions?
Printf, scanf, clrscr, gotoxy, string handling functions and file handling functions
6. What is function prototype declaration?
A function declaration is also known as function prototype declaration which contains function
return type, function name, parameter list and terminating semicolon
A3: Flowchart is diagram representation of algorithms used to show flow of data in program using various
symbols.
Q9: What is the range of integer constant for compilers like Turbo
C? A9: Range: -32768 to 32767.
Input/Output statements.
Q1: What is the output of printf("%d") ?
A1: When we write printf("%d", n); this means compiler will print the value of n. But here, there is
nothing after %d so compiler will show in output window garbage value.
Q5: What are the maximum and minimum possible ranges of values for long and short type?
A5: If the int variable is created by default as a “long‟ type it will have a possible range of values from a
maximum of +214748347 and a minimum of -2147483648. For “short‟ type the maximum and
minimum values +327676 and minimum -32768.
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to
2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
Q6: What exactly is a “variable scope‟, “local variables” and “global variables”?
A6: The extent to which a variable is accessible in a program is called the “variable scope”. Variables
declared internally inside a function are known as “local” variables.
Variables declared externally outside a function are known as “global” variables.
Q6:What is Preprocessor?
A6:preprocessor is a program which is invoked before the compilation process. it access input data and
process output data which has been used as input data to the other program like compiler.
Q10: What is the function of break statement when used within switch?
A10: The break statement when used in aswitch takes the control outside the switch .
Q5. What is scope & storage allocation of extern and global variables?
A5: Extern variables: belong to the External storage class and are stored in the main memory.
extern is used when we have to refer a function or variable that is implemented in other file in the
same project. The scope of the
extern variables is Global. Global variables: are variables which are declared above the main( )
function. These variables are accessible throughout the program. They can be accessed by all the
functions in the program. Their default value is zero.
Q6. What is scope & storage allocation of static and local variables?
A6. Static variables: Memory is allocated at the beginning of the program execution and it is
reallocated only after the program terminates. The scope of the static variables is local to the
block in which the variables are defined.
Local variables: are variables which are declared within any function or a block. They can be
accessed only by function or block in which they are declared. Their default value is a garbage
value.
Q7. What are storage memory, default value, scope and life of Automatic and Register storage class?
A7. 1. Automatic storage class: Storage : main memory. Default value : garbage value. Scope : local
to the block in which the variable is defined. Lifetime : till control remains within the block.
2. Register storage class: Storage : CPU registers. Default value : garbage value.Scope : local to the
block in which the variable is defined. Lifetime : till control remains within the block.
Q8. What are storage memory, default value, scope and life of Static and External storage class?
A8. Static storage class:Storage : main memory.Default value : zeroScope : local to the block in
which the variable is defined.Lifetime : till the value of the variable persists between different function
calls.
2. External storage class:Storage : main memoryDefault value : zeroScope : globalLifetime : as long
as the program execution doesn't come to an end.
Q3. What are header files? Are functions declared or defined in header files ?
A3: Functions and macros are declared in header files. Header files would be included in source files by
the compiler
at the time of compilation. Header files are included in source code using #include directive A header
file may contain declarations of sub-routines, functions, macros and also variables which we may want
to use in our program. Header files help in reduction of repetitive code
4. What are the differences between getchar() and scanf() functions for reading strings?
A4: scanf();-Entering of each character should be followed by return key 2. Continuous stream of
characters cannot be directly supplied using scanf function.
getchar():- 1. Need not type return key. 2. Continuous stream of characters can be directly supplied using
getchar function
8. 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.
we use a while loop when a statement or group of statements which may have to be executed a number
of times to complete their task. The controlling expression represents the condition
20. How does the type float differ from double in C language ?
Float data type refers real number in single precision and has 6 decimal digits. It takes 4 bytes in
memory to refer values ranging from 3.4e-38 to 3.4e+38
double data type also refers to real number but in double precision and has 12 decimal digits. It takes 8
bytes of memory to refer values ranging from 1.7e-308 to 1.7e+308