key features in the C programming language
Answer :
Portability – Platform independent language. Modularity – Possibility to break down large programs into small modules.What are reserved words with a programming language?
Answer :
The words that are part of the slandered 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.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.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.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 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.What is NULL pointer?
Answer :
NULL is used to indicate that the pointer doesn’t point to a valid location. Ideally, we should initialize pointers as NULL if we don’t know their value at the time of declaration. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program.What is the difference between static & global variables?
Answer :
Global variables are variables which are defined outside the function. The scope of global variables begins at the point where they are defined and lasts till the end of the file/program. Whereas, static global variables are private to the source file where they are defined and do not conflict with other variables in other source files which would have the same name.What is Memory Leak in C?
Answer :
A memory leak occurs when programmers create a memory in the heap and forget to delete it. It decreases the efficiency of the performance of the system.What is Static and Dynamic memory allocation?
Answer :
Static memory allocation happens at compile-time, and memory can’t be increased while executing the program. Whereas in case of dynamic memory allocation, this happens at runtime and memory can be increased while executing the program. Static memory allocation is used in arrays & dynamic memory allocation is used in Linked Lists. Static memory allocation uses more memory space to store a variable.What is the difference between while (0) and while (1)?
Answer :
While(1) is an infinite loop which will run till a break statement occurs. Similarly, while(2), while(3), while(255) etc will all give infinite loops only. Whereas, While(0) does the exact opposite of this. When while(0) is used, it means the conditions will always be false. Thus, as a result, the program will never get executed.What is the difference between Pass by value and Pass by reference?
Answer :
In pass by value, changes made to the arguments in the called function will not be reflected in the calling function. Whereas in pass by reference, the changes made to the arguments in the called function will be reflected in the calling function.Difference between malloc() and calloc() functions?
Answer :
malloc and calloc are library functions that allocate memory dynamically, which means that memory is allocated during the runtime from the heap segment. Malloc and Calloc differ in the number of arguments used, their initialization methods and also in the return values.What is the difference between Arrays and Pointers?
Answer :
A few differences between Arrays and Pointers are: An array is a collection of elements of similar data type whereas the pointer is a variable that stores the address of another variable. An array size decides the number of variables it can store whereas; a pointer variable can store the address of only one variable in it. Arrays can be initialized at the definition, while pointers cannot be initialized at the definition.What is the difference between a structure and a Union?
Answer :
All the members of a structure can be accessed simultaneously but union can access only one member at a time Altering the value of a member will not affect the other members of the structure but where it affects the members of a union Lesser memory is needed for a union variable than a structure variable of the same type.Compare and contrast compilers from interpreters.
Answer :
Compilers and interpreters often deal with how program codes are executed. Interpreters execute program codes one line at a time, while compilers take the program as a whole and convert it into object code, before executing it. The key difference here is that in the case of interpreters, a program may encounter syntax errors in the middle of execution, and will stop from there. On the other hand, compilers check the syntax of the entire program and will only proceed to execution when no syntax errors are found.What is a pointer on pointer?
Answer :
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.
Answer :
Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.What is keyword auto for?
Answer :
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?
Answer :
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?
Answer :
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 “ “?
Answer :
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?
Answer :
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 -5What is a static variable?
Answer :
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?
Answer :
A pointer pointing to nothing is called so. Eg: char *p = NULL;What is the purpose of extern storage specifier?
Answer :
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().
Answer :
Prints the formatted output onto the character array.What is the meaning of base address of the array?
Answer :
The starting address of the array is called as the base address of the array.When should we use the register storage specifier?
Answer :
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?
Answer :
S++, as it is single machine instruction (INC) internally.What is a dangling pointer?
Answer :
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?
Answer :
It is used to alias the existing type. Also used to simplify the complex declaration of the type.What is lvalue and rvalue?
Answer :
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?
Answer :
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?
Answer :
Yes, it can be but cannot be executed, as the execution requires main() function definition.What is the advantage of declaring void pointers?
Answer :
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?
Answer :
Every local variable by default being an auto variable is stored in stack memory.What is a nested structure?
Answer :
A structure containing an element of another structure as its member is referred so.What is the difference between variable declaration and variable definition?
Answer :
Declaration associates type to the variable whereas definition gives the value to the variable.What is a self-referential structure?
Answer :
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?
Answer :
No, the header file only declares function. The definition is in library which is linked by the linker.Explain modular programming.
Answer :
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?
Answer :
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?
Answer :
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().
Answer :
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?
Answer :
Escape it using \ (backslash).Does a break is required by default case in switch statement?
Answer :
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 use -> (arrow) operator?
Answer :
If the structure/union variable is a pointer variable, to access structure/union elements the arrow operator is used.What are bit fields?
Answer :
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?
Answer :
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?
Answer :
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?
Answer :
It compares two strings by ignoring the case.Describe the file opening mode “w+”?
Answer :
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?
Answer :
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?
Answer :
No, it is a structure defined in stdio.h.What is reminder for 5.0 % 2?
Answer :
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?
Answer :
There is only one operator and is conditional operator (? : ).Which key word is used to perform unconditional branching?
Answer :
gotoWhat is a pointer to a function and give the general syntax for the same?
Answer :
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 (,).
Answer :
Comma operator can be used to separate two or more expressions. Eg: printf(“hi”) , printf(“Hello”);What is a NULL statement?
Answer :
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?
Answer :
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?
Answer :
Opiton –lm to be used as > gcc –lm <file.c>Which operator is used to continue the definition of macro in the next line?
Answer :
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?
Answer :
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?
Answer :
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?
Answer :
realloc()Define an array.
Answer :
Array is collection of similar data items under a common name.What are enumerations?
Answer :
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?
Answer :
fseek()What is a variable?
Answer :
A variable is the name storage.Who designed C programming language?
Answer :
Dennis M Ritchie.C is successor of which programming language?
Answer :
BWhat is the full form of ANSI?
Answer :
American National Standards Institute.Which operator can be used to determine the size of a data type or variable?
Answer :
sizeofCan we assign a float variable to a long integer variable?
Answer :
Yes, with loss of fractional part.Is 068 a valid octal number?
Answer :
No, it contains invalid octal digits.What it the return value of a relational operator if it returns any?
Answer :
Return a value 1 if the relation between the expressions is true, else 0.How does bitwise operator XOR works?
Answer :
If both the corresponding bits are same it gives 0 else 1.What is an infinite loop?
Answer :
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.
Answer :
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?
Answer :
Local variables get garbage value and global variables get a value 0 by default.Can a pointer access the array?
Answer :
Pointer by holding array’s base address can access the array.What are valid operations on pointers?
Answer :
The only two permitted operations on pointers are Comparision Addition/Substraction (excluding void pointers)What is a string length?
Answer :
It is the count of character excluding the ‘\0’ character.What is the built-in function to append one string to another?
Answer :
strcat() form the header string.hWhich operator can be used to access union elements if union variable is a pointer variable?
Answer :
Arrow (->) operator.Explain about ‘stdin’.
Answer :
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.
Answer :
fclose()What is the purpose of #undef preprocessor?
Answer :
It be used to undefine an existing macro definition.Define a structure.
Answer :
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?
Answer :
__STDC__What is typecasting?
Answer :
Typecasting is a way to convert a variable/constant from one type to another type.What is recursion?
Answer :
Function calling itself is called as recursion.Which function can be used to release the dynamic allocated memory?
Answer :
free()What is the first string in the argument vector w.r.t command line arguments?
Answer :
Program name.How can we determine whether a file is successfully opened or not using fopen() function?
Answer :
On failure fopen() returns NULL, otherwise opened successfully.What is the output file generated by the linker?
Answer :
Linker generates the executable file.What is the maximum length of an identifier?
Answer :
Ideally it is 32 characters and also implementation dependent.What is the default function call method?
Answer :
By default the functions are called by value.Functions must and should be declared. Comment on this.
Answer :
Function declaration is optional if the same is invoked after its definition.When the macros gets expanded?
Answer :
At the time of preprocessing.Can a function return multiple values to the caller using return reserved word?
Answer :
No, only one value can be returned to the caller.What is a constant pointer?
Answer :
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?
Answer :
VoidCan the structure variable be initialized as soon as it is declared?
Answer :
Yes, w.r.t the order of structure elements only.Is there a way to compare two structure variables?
Answer :
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?
Answer :
Strstr()What is difference between far and near pointers?
Answer :
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?
Answer :
No, we cannot.Which control loop is recommended if you have to execute set of statements for fixed number of times?
Answer :
for – Loop.What is a constant?
Answer :
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?
Answer :
No, we need to use both the keyword ‘struct’ and the tag name.Can the main() function left empty?
Answer :
Yes, possibly the program doing nothing.Can one function call another?
Answer :
Yes, any user defined function can call any function.Apart from Dennis Ritchie who the other person who contributed in design of C language.
Answer :
Brain KernighanWhat is the output of the following code snippet?
#include<stdio.h> main() { int const a = 5; a++; printf(“%d”,a); }Answer :
Compile error - constant variable cannot be modified.What is the output of the following code snippet?
#include<stdio.h> main() { const int a = 5; a++; printf("%d", a); }Answer :
Compile error - constant variable cannot be modified.What is the output of the below code snippet?
#include<stdio.h> main() { char s[]="hello", t[]="hello"; if(s==t){ printf("eqaul strings"); } }Answer :
No output, as we are comparing both base addresses and they are not same.What is the output of the below code snippet?
#include<stdio.h> main() { int a = 5, b = 3, c = 4; printf("a = %d, b = %d\n", a, b, c); }Answer :
a = 5, b = 3, as there are only two format specifiers for printing.What is the output of the below code snippet?
#include<stdio.h> main() { int a = 1; float b = 1.3; double c; c = a + b; printf("%.2lf", c); }Answer :
2.30, addition is valid and after decimal with is specified for 2 places.What is the outpout of the following program?
#include<stdio.h> main() { enum { india, is = 7, GREAT }; printf("%d %d", india, GREAT); }Answer :
0 8, enums gives the sequence starting with 0. If assigned with a value the sequence continues from the assigned value.What is the output of the following code snippet?
#include<stdio.h> main() { char c = 'A'+255; printf("%c", c); }Answer :
A, the range of ASCII values for the ASCII characters is 0-255. Hence the addition operation circulates back to ‘A’What is the output of the following code snippet?
#include<stdio.h> main() { short unsigned int i = 0; printf("%u\n", i--); }Answer :
0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented.What is the output of the below code snippet?
#include<stdio.h> main() { unsigned x = 5, y = &x, *p = y+0; printf("%u",*p); }Answer :
5, as p holds the address of x which is y+0What is your comment on the below C statement?
signed int *p = (int*)malloc(sizeof(unsigned int));Answer :
Option (d), as the size of int and unsigned is same, no problem in allocating memory.What is the output of the following code snippet?
#include<stdio.h> main() { int x = 5; if(x==5) { if(x==5) break; printf("Hello"); } printf("Hi"); }Answer :
compile error, keyword break can appear only within loop/switch statement.What is the output of the following code snippet?
#include<stdio.h> main() { int x = 5; if(x = 5) { if(x = 5) break; printf("Hello"); } printf("Hi"); }Answer :
compile error, keyword break can appear only within loop/switch statement.What is the output of the following code snippet?
#include<stdio.h> main() { int x = 5; if(x=5) { if(x = 5) printf("Hello"); } printf("Hi"); }Answer :
HelloHi, both the if statement’s expression evaluate to be true.What is the output of the below code snippet?
#include<stdio.h> main() { for(;;)printf("Hello"); }Answer :
infinite loop, with second expression of ‘for’ being absent it is considered as true by default.What is the output of the below code snippet?
#include<stdio.h> main() { for()printf("Hello"); }Answer :
Compiler error, semi colons need to appear though the expressions are optional for the ‘for’ loop.What is the output of the below code snippet?
#include<stdio.h> main() { for(1;2;3) printf("Hello"); }Answer :
infinite loop, as the second expression is non-0, hence the condition is always true.What is the output of the following program?
#include<stdio.h> void f() { static int i; ++i; printf("%d", i); } main() { f(); f(); f(); }Answer :
1 2 3, A static local variables retains its value between the function calls and the default value is 0.What is the output of the following code snippet?
#include<stdio.h> main() { int *p = 15; printf("%d",*p); }Answer :
Runtime error, as the pointer variable is not holding proper address, writing/reading the data from the same raises runtime error.What is the output of the following program?
#include<stdio.h> main() { register int x = 5; int *p; p = &x; x++; printf("%d",*p); }Answer :
Compile error, we cannot take the address of a register variable.What is the output of the following program?
#include<stdio.h> main() { int x = 65, *p = &x; void *q = p; char *r = q; printf("%c",*r); }Answer :
A, void pointer is a generic pointer and can hold any variable’s address. ASCII character for the value 65 is ‘A’What is the output of the following program?
#include<stdio.h> void f() { printf(“Hello\n”); } main() { ; }Answer :
No output, apart from the option (a) rest of the comments against the options are invalid.What is the output of the following program?
#include<stdio.h> main() { printf("\"); }Answer :
Compile error, Format string of printf is not terminated.What is the output of the following program?
#include<stdio.h> { int x = 1; switch(x) { default: printf("Hello"); case 1: printf("hi"); break; } }Answer :
Hi, control reaches default-case after comparing the rest of case constants.What is the output of the following program?
#include<stdio.h> main() { struct { int x;} var = {5}, *p = &var; printf("%d %d %d",var.x,p->x,(*p).x); }Answer :
5 5 5, the two possible ways of accessing structure elements using pointer is by using -> (arrow operator) OR *.What is the output of the following program?
#include<stdio.h> void swap(int m, int n) { int x = m; m = n; n = x; } main() { int x = 5, y = 3; swap(x,y); printf("%d %d", x, y); }Answer :
5 3, call by value mechanism can’t alter actual arguments.What will be printed for the below statement?
#include<stdio.h> main() { printf("%d",strcmp("strcmp()","strcmp()")); }Answer :
0, strcmp return 0 if both the strings are equalWhat is the following program doing?
#include<stdio.h> main() { FILE *stream = fopen("a.txt",'r'); }Answer :
Compile error, second argument for fopen is invalid, should be a string.What is the output of the following program?
#include<stdio.h> main() { int r, x = 2; float y = 5; r = y%x; printf("%d", r); }Answer :
Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real number.What is the size of the following union definition?
#include<stdio.h> union abc { char a,b,c,d,e,f,g,h; int i; }abc; main() { printf( "%d", sizeof( abc )); }Answer :
union size is biggest element size of it. All the elements of the union share common memory.What is the value of ‘y’ for the following code snippet?
#include<stdio.h> main() { int x = 1; float y = x>>2; printf( "%f", y ); }Answer :
0, data bits are lost for the above shift operation hence the value is 0.What is the output of the following program?
#include<stdio.h> main() { float t = 2; switch(t) { case 2: printf("Hi"); default: printf("Hello"); } }Answer :
Error, switch expression can’t be float value.What is the output of the following program?
#include<stdio.h> main() { int i = 1; while(++i <= 5) printf("%d ",i++); }Answer :
2 4, at while first incremented and later compared and in printf printed first and incremented later.What is the output of the following program?
#include<stdio.h> main() { int i = 1; while( i++<=5 ) printf("%d ",i++); }Answer :
2 4 6, at while first compared and later incremented and in printf printed first and incremented later.What is the output of the following program?
#include<stdio.h> main() { int i = 1; while(i++<=5); printf("%d ",i++); }Answer :
6, there is an empty statement following ‘while’.What is the output of the following program?
#include<stdio.h> main() { int x = 1; do printf("%d ", x); while(x++<=1); }Answer :
1 2, do..while is an entry control loop. As the expression x++ is post form loop continues for 2nd time also.What is the output of the following program?
#include<stdio.h> main() { int a[] = {1,2}, *p = a; printf("%d", p[1]); }Answer :
2, as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’.What is the output of the following program?
#include<stdio.h> main() { int a[3] = {2,1}; printf("%d", a[a[1]]); }Answer :
1, The inner indirection evaluates to 1, and the value at index 1 for outer indirection is 1.What is the output of the following program?
#include<stdio.h> main() { int a[3] = {2,,1}; printf("%d", a[a[0]]); }Answer :
Compile error, invalid syntax in initializing the array.What is the output of the following program?
#include<stdio.h> main() { int a[] = {2,1}; printf("%d", *a); }Answer :
2, as ‘a’ refers to base address.What is the output of the following program?
#include<stdio.h> main() { int i = 1; Charminar: printf("%d ",i++); if(i==3) break; if(i<=5) goto Charminar; }Answer :
Compile error, wrong place for ‘break’ to appear.What is the output of the following program?
#include<stdio.h> main() { int i = 13, j = 60; i ^= j; j ^= i; i ^= j; printf("%d %d", i, j); }Answer :
60 13, its swapping.What is the output of the following program?
#include<stdio.h> main() { union abc { int x; char ch; }var; var.ch = 'A'; printf("%d", var.x); }Answer :
65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII value is 65 and is printed.Choose the application option for the following program?
#include<stdio.h> main() { int *p, **q; printf("%u\n", sizeof(p)); printf("%u\n", sizeof(q)); }Answer :
Irrespective of any data type every type of pointer variable occupies same amount of memory.What is the output of the following program?
#include<stdio.h> int* f() { int x = 5; return &x; } main() { printf("%d", *f()); }Answer :
It is invalid to return local variable address as the local variable gets removed after the functions execution is completed.What is the output of the following program?
#include<stdio.h> main() { char *p = NULL; printf("%c", *p); }Answer :
It is invalid to access the NULL address hence giving run time error.What is the output of the following program?
#include<stdio.h> void f() { static int i = 3; printf("%d ", i); if(--i) f(); } main() { f(); }Answer :
As the static variable retains its value from the function calls, the recursion happens thrice.What is the output of the following program?
#include<stdio.h> main() { }Answer :
It is valid to have main() function empty, therefore producing no displayable output.What is the output of the following program?
#include<stdio.h> void f(int const i) { i = 5; } main() { int x = 10; f(x); }Answer :
Error in the statement i = 5. We cannot modify a constant as in statement i = 5.What is the output of the following program?
#include<stdio.h> int x = 5; int* f() { return &x; } main() { *f() = 10; printf("%d", x); }Answer :
The returned address is global variables and 10 being stored in it. Therefore x is 10.What is the output of the below code snippet?
#include<stdio.h> main() { printf("%d", -11%2); }Answer :
Modulus (%) operator is meant to give reminder for integer division.Does both the loops in the following programs prints the correct string length?
#include<stdio.h> main() { int i; char s[] = "hello"; for(i = 0; s[i]; ++i); printf("%d ", i); i = 0; while(s[i++]); printf("%d ", i); }Answer :
In while loop ‘i’ gets incremented after checking for ‘\0’, hence giving 1 more than the length.For the below definition what is the data type of ‘PI’.
#define PI 3.141Answer :
The text associated with the macro name gets expanded at the line of call. The expanded text is by default a double constant whereas no type is associated with PI.What is the output of the following program?
#include<stdio.h> main() { int a[] = {10, 20, 30}; printf("%d", *a+1); }Answer :
*a refers to 10 and adding a 1 to it gives 11.What is the output of the following program?
#include<stdio.h> void f(int a[]) { int i; for(i = 0; i<3; i++) a[i]++; } main() { int i,a[] = {10, 20, 30}; f(a); for(i = 0; i<3; ++i) { printf("%d ",a[i]); } }Answer :
11 21 31, Arrays are always passed by reference.What is the output of the following program?
#include<stdio.h> main() { char *s = "Hello, " "World!"; printf("%s", s); }Answer :
Hello, World!What is the output of the following program?
#include<stdio.h> main() { fprintf(stdout,"Hello, World!"); }Answer :
Compile error, stdout is the identifier declared in the header file stdio.h, need to include the same.What is the output of the following program?
#include<stdio.h> main() { fprintf(stdout,"Hello, World!"); }Answer :
Hello, World!What is the output of the following program?
#include<stdio.h> main() { char s[] = "Fine"; *s = 'N'; printf("%s", s); }Answer :
NineWhat is the output of the following program?
#include<stdio.h> main() { char *s = "Fine"; *s = 'N'; printf("%s", s); }Answer :
*s = ’N’, trying to change the character at base address to ‘N’ of a constant string leads to runtime error.What is the output of the following program?
#include<stdio.h> main() { int x; float y; y = x = 7.5; printf("x=%d y=%f", x, y); }Answer :
7 7.000000What is the output of the following program?
#include<stdio.h> main() { char s1[50], s2[50] = "Hello"; s1 = s2; printf("%s", s1); }Answer :
‘s1’ refers to base address and is constant. Hence raising to ‘lvalue’ required compile time error.What is the output of the following program?
#include<stdio.h> int main(); void main() { printf("Okay"); }Answer :
It’s compile error as the declaration of main() mismatches with the definition.What is the output of the following program?
#include<stdio.h> void main() { char *s = "C++"; printf("%s ", s); s++; printf("%s", s); }Answer :
C++ ++What is the output of the following program?
#include<stdio.h> void main() { char s[] = "C++"; printf("%s ",s); s++; printf("%s",s); }Answer :
Compile error, ‘s’ refers to a constant address and cannot be incremented.What is the output of the following statement?
#include<stdio.h> main() { printf("%d", -1<<1 ); }Answer :
A negative number stored in two’s compliment of positive number. After shifting we get 1110, which is equivalent to -2.What is the output of the following program?
#include<stdio.h> main() { int x = 3; x += 2; x =+ 2; printf("%d", x); }Answer :
+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.What is the output of the following program?
#include<stdio.h> main() { char *s = "Abc"; while(*s) printf("%c", *s++); }Answer :
Loop continues until *s not equal to ‘\0’, hence printing “Abc” where character is fetched first and address is incremented later.What is the output of the following program?
#include<stdio.h> main() { char s[20] = "Hello\0Hi"; printf("%d %d", strlen(s), sizeof(s)); }Answer :
5 20, length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.What is the output of the following program?
#include<stdio.h> main() { char s[] = "Hello\0Hi"; printf("%d %d", strlen(s), sizeof(s)); }Answer :
5 9, length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.What is the output of the following statement?
#include<stdio.h> main() { printf("%d", !0<2); }Answer :
Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.What is the output of the following program?
#include<stdio.h> main() { struct student { int num = 10; }var; printf("%d", var.num); }Answer :
Compile error, structure elements cannot be initialized.What is the output of the following program?
#include<stdio.h> #define sqr(i) i*i main() { printf("%d %d", sqr(3), sqr(3+1)); }Answer :
9 7, the equivalent expansion is -> printf("%d %d",3*3,3+1*3+1);What is the output of the following program?
#include<stdio.h> main() { char *s = "Hello"; while(*s!=NULL) printf("%c", *s++); }Answer :
HelloWhat is the output of the following program?
#include<stdio.h> main() { #undef NULL char *s = "Hello"; while(*s != NULL) { printf("%c", *s++); } }Answer :
Compile error: NULL is undeclared.In normalized form, if the binary equivalent of 5.375 is “0100 0000 1010 1100 0000 0000 0000 0000” then what will be the output of the program in Intel core machine?
#include<stdio.h> #include<math.h> int main () { float a = 5.375; char *p; int i; p = (char*)&a; for(i=0; i <= 3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; }Answer :
00 00 AC 40Which header statement is missing in the given below program to get the desired output?
#include<stdio.h> #include<math.h> int main () { double x = 1234321; double result = sqrt(x); printf("The square root of %.2lf is %.2lf\n", x, result); return 0; }Answer :
#include<math.h>Write the program that round off x value (a float value) to an int value to return the output value 4,
Answer :
#include <math.h> #include <stdio.h> int main() { float x = 3.6; int y = (int)(x + 0.5); printf ("Result = %d\n", y ); return 0; }The given below program allocates the memory, what function will you use to free the allocated memory?
#include<stdio.h> #include<stdlib.h> #define MAXROW 4 # define MAXCOL 5 int main () { int **p, i, j p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }Answer :
free() is the function in C language to release the allocated memory by any dynamic memory allocating built in library function.In the given below code, if a short int value is 5 byte long, then how many times the while loop will get executed?
#include<stdio.h> int main () { int j = 1; while(j <= 300) { printf("%c %d\n", j, j); j++; } return 0; }Answer :
If while(j <= 300),then whatever the size short int value, the while loop condition will execute until j value becomes 300.How many times the given below program will print "India"?
#include<stdio.h> int main () { int x; for(x=-1; x<=20; x++)int i; { if(x < 10) continue; else break; printf("India"); }Answer :
0 timerHow many times the given below program will print "IndiaPIN"?
#include<stdio.h> int main () { printf("IndiaPIN"); main(); return 0; }Answer :
A stack over flow comes when over loaded memory is used by the call stack. Here, main() function is called repeatedly and its return address stores in the stack. When stack memory get filled, it displays the error “stack overflow”.In the given below code, the function fopen()uses "r" to open the file “source.txt” in binary mode for which purpose?
#include<stdio.h> int main () { FILE *fp; fp = fopen("source.txt", "r"); return 0; }Answer :
To open a file in C programming, we can use library function fopen(). In the given above code, fopen() function is opening a file “source.txt” for reading. Here, “r” stands for reading. If, fopen() function does not find any file for reading, returns NULLWhich scanf() statement will you use to scan a float value (a) and double value (b)?
Float a; Double b;Answer :
scanf("%f %lf", &a, &b);Choose the correct statement that is a combination of these two statements,
Statement 1: char *p; Statement 2: p = (char*) malloc(100);Answer :
char *p = (char*)malloc(100);In the given below code, the P2 is
Typedef int *ptr; ptr p1, p2;Answer :
Integer pointerIn the following code, what is 'P'?
Typedef char *charp; const charp P;Answer :
P is a constantWhat is x in the following program?
#include<stdio.h> int main () { typedef char (*(*arrfptr[3])())[10]; arrfptr x return 0; }Answer :
x is an array of three function pointersWhat will be the resultant of the given below program?
#include<stdio.h> #include<stdarg.h> Void fun(char *msg, ...); int main () { fun("IndiaMAX", 1, 4, 7, 11, 0); return 0; } void fun(char *msg, ...) { va_list ptr;{ int num; va_start(ptr, msg); num = va_arg(ptr, int); num = va_arg(ptr, int); printf("%d", num); } }Answer :
va_list ptr is an argument pointer that traverse through the variable arguments passed in the function, where, va_start points 'ptr' to the first argument (IndiaMix). In each call to the va_arg, ptr shift to the next variable argument and after two calls ptr ends up at '7' and return the number '4'.Which files will get closed through the fclose() in the following program?
#include<stdio.h> int main () { FILE *fs, *ft, *fp; fp = fopen("ABC", "r"); fs = fopen("ACD", "r"); ft = fopen("ADF", "r"); fclose(fp, fs, ft); return 0; }Answer :
The syntax of fclose() function is wrong; it should be int fclose(FILE *stream); closesthe stream. Here, fclose(fp, fs, ft); is using separator(,) which returns error by sayingthat extra parameter in call to fclose() function.What will be the output of the following program?
#include<stdio.h> int main() { const int i = 0; printf("%d\n", i++); return 0; }Answer :
Return error It is because ++needs a value and a const variable can’t be modified.Which printf() statement will you use to print out a (float value) and b (double value)?
Float a = 3.14; Double b = 3.14;Answer :
printf("%f %lf", a, b);What will be the output of the following program?
#include<stdio.h> int main() { const int x = 5; const int *ptrx; ptrx = &x; *ptrx = 10; printf("%d\n", x); return 0; }Answer :
The program will return errorWhat do the following statement defines?
int *ptr[10];Answer :
ptr is a array of 10 pointers to integersWhat is the role of "r+" on the file "NOTES.TXT" in the given below code?
#include<stdio.h> int main () { FILE *fp; fp = fopen("NOTES.TXT", "r+"); return 0; }Answer :
"r+" open the file "NOTES.TXT" file for reading & writing bothIn the given below code, what will be return by the function get ()?
#include<stdio.h> int get(); int main() { const int x = get(); printf("%d", x); return 0; } int get() { return 40; }Answer :
Firstly, “int get()” which is a get() function prototype returns an integer value without any parameters. Secondly, const int x = get(); The constant variable x is declared as an integer data type and initialized with the value of get(). Hence, the value of get() is 40, printf("%d", x); will print the value of x, that means; 40. So, the program output will be 40.What will be the output of the given below program in TurboC?
#include<stdio.h> int fun(int **ptr); int main() { int i = 10, j = 20; const int *ptr = &i; printf(" i = %5X", ptr); printf(" ptr = %d", *ptr); ptr = &j; printf(" j = %5X", ptr); printf(" ptr = %d", *ptr); return 0; }Answer :
i = FFE4 ptr = 10 j = FFE2 ptr = 20What will be the output of the given below code?
#include<stdio.h> int main() { const int *ptr = &i; char str[] = "Welcome"; s = str; while(*s) printf("%c", *s++); return 0; }Answer :
WelcomeIn the given below code, what will be the value of a variable x?
#include<stdio.h> int main() { int y = 100; const int x = y; printf("%d\n", x); return 0; }Answer :
Although, integer y = 100; and constant integer x is equal to y. here in the given above program we have to print the x value, so that it will be 100.If, the given below code finds the length of the string then what will be the length?
#include<stdio.h> int xstrlen(char *s) { int length = 0; while(*s!='\0') {length++; s++;} return (length); } int main() { char d[] = "IndiaMAX"; printf("Length = %d\n", xstrlen(d)); return 0; }Answer :
Code returns the length 8In the given below statement, what does the “arr” indicate?
char *arr[30];Answer :
arr is a array of 30 character pointersIn the given below statement, what does the “pf” indicate?
int (*pf)();Answer :
pf is a pointer of a function which return intWhat is the output of the following program?
#include<stdio.h> main () { int i, j; for(i = 5, j = 1; i>j; i--, ++j) }Answer :
5 1, 4 2 - The condition fails when i = j = 3.What is the output of the following program?
#include<stdio.h> main () { int a = 1, b = 2, *p = &a, *q = &b, *r = p; p = q; q = r; printf("%d %d %d %d\n",a,b,*p,*q); }Answer :
1 2 2 1, the pointers are swapped not the values.What is the output of the following program?
#include<stdio.h> void g(void) { } main () { void (*f)(void); f = g; f(); }Answer :
Hello, every line is a valid statement.What is the output of the following program?
#include<stdio.h> int f(int i) { } main () { printf("%d",f(f(f(f(f(1)))))); }Answer :
1, the return value is post increment expression as it always receives 1 and returns 1.What is the output of the following program?
#include<stdio.h> main () { static int i = 1; if(i--) { printf("%d ",i); main(); } }Answer :
0, static variable retains its value between the function calls.What is the output of the following program?
#include<stdio.h> main () { printf(); }Answer :
Program fails compilationDoes the following program compiles?
#include “stdio.h”Answer :
It compiles successfully and can’t be executed. Use gcc –c option to compile the same with command line compiler (UNIX/Linux) or just compile without build in an IDE.What is the output of the following program?
#include<stdio.h> main () { int *p = NULL; #undef NULL if(p==NULL) printf("NULL"); else printf("Nill"); }Answer :
Compile error, as the macro is undefined NULL is considered as undeclared.What is the output of the following program?
main() { puts(__DATE__); }Answer :
Prints date, __DATE__ is a compiler defined macro.