Académique Documents
Professionnel Documents
Culture Documents
C Fundamental Test 1
Hide Answer
Explanation:
Hide Answer
Explanation:
Compiler used for UNIX is 'cc' their full form is C compiler. gcc is compiler for linux.
Borland and vc++ is compiler for windows.
3) Which of the following is a logical AND operator?
a. ||
b. !
c. &&
d. None of the above
Hide Answer
Explanation:
The && is called logical AND operator. If both operands are non-zero, then the condition
becomes true.
The || is called logical OR operator. If any of the two operands are non-zero, then the
condition becomes true.
The ! is called logical NOT operator. It is used for reversing the logic state of its operand.
Hide Answer
Explanation:
The %lf format specifier is used for printing the double value in a C program.
Hide Answer
Explanation:
The memory allocated by malloc(), calloc(), or realloc() function is deallocated by using the
library function free(var-name).
Hide Answer
Explanation:
Explanation:
Hide Answer
Explanation:
In C language,"\n" is the escape sequence for printing a new line character. For a statement
printf("\\n"); statement , "\\" symbol will be printed as "\" and "n" is known as a common
symbol.
a. 1
b. 1 and 3
c. 2
d. 1 and 2
Hide Answer
Explanation:
Hide Answer
Explanation:
Header file stdio.h is used for defining the macros, variable and various functions for
performing input and output operation in C-language.
Hide Answer
For giving the comment in single line two immediate forward slashes are used. For a multi
line comment it begins with /* and should be terminated with */.
12) What is the data type of "PI" for the below statement:
1. #define PI 3.141
a. Float data type
b. Double datatype
c. There is no data type associated with PI
d. Syntax error, semi colon is missing with definition of PI
Hide Answer
Explanation:
Text associated with macro statement gets expanded at line of call. The expanded text is by
default a constant with no data type associated with PI.
13) Which operator can be used for accessing the value stored at
address of a pointer variable?
a. #
b. *
c. &&
d. @
Hide Answer
Explanation:
Hide Answer
Explanation:
Hide Answer
Explanation:
Explanation:
Show Answer
Hide Answer
Explanation:
The C variables are case sensitive. This means that variables sal, Sal and SAL would be
treated as different variables in C.
Hide Answer
Explanation:
A character variable can at a time store only one character. In fact, if we execute the
following statements, what gets stored in variable ch is not really the character constant,
but the ASCII value of 'A', which is 65.
1. char ch;
2. ch= 'A';
20) How would you round off a value from 1.66 to 2.0?
a. floor(1.66)
b. ceil(1.66)
c. roundup(1.66)
d. roundto(1.66)
Hide Answer
Explanation:
The ceil(1.66) is used for round off a value from 1.66 to 2.0. The ceil() returns upper value
of a fractional part and floor() returns lower value.
next →← prev
C Control Statements Test 1
C control statements test paper contains questions from decision statement: if-else and
switch, loop statement: for loop, while loop & do-while loop and jump statement: break
and continue.
Hide Answer
Explanation:
Hide Answer
Explanation:
In program the x is initialized with -1. As x < 5 (since x is -1) it will start with continue
statement.
Continue means "stop the current iteration and proceed to the next iteration". Therefore
x becomes 0 now. This will take place until x becomes 5.
Now if the value of x=5, it will enter the else part where it encounters the break
statement, as a result it will come out of for loop. Hence it will not go to printf statement.
Hide Answer
Explanation:
The size of short int which is 2 byte wide does not affect the while() loop operation.
Hide Answer
Explanation:
In program 5th line i.e. if(i = 8) && if(j = 24) the "Expression syntax" error occur.
Hide Answer
Explanation:
6) Find out the error, if any in the while loop of below program.
1. #include<stdio.h>
2. int main()
3. {
4. int j=1;
5. while()
6. {
7. printf("%d\n", j++);
8. if(j>5)
9. break;
10. }
11. return 0;
12. }
a. There should be a semicolon in the while statement
b. The while loop should be replaced with do-while loop
c. There should be a condition in the while loop
d. No error
Hide Answer
Explanation:
In program "Expression syntax" error occur because the while() loop must have conditional
expression.
Therefore for removing the ?Expression syntax? error there should be a condition in the
while loop.
Hide Answer
Explanation:
No, if scanf() statement is used then the carriage return tells the compiler to read the input
from buffer after the ENTER key is pressed by the user. Therefore the value of carriage
return (\r) is not get stored in memory.
8) Find out whether both the loops in a program prints the correct
string length?
1. #include<stdio.h>
2. main()
3. {
4. int j;
5. char s[] = "javaTpoint";
6.
7. for(j=0; s[j]; ++j);
8. printf("%d \n", j);
9.
10. j=0;
11. while(s[j++]);
12. printf("%d ", j);
13. }
a. Yes, both the loops prints the correct string length
b. Only while loop prints the correct string length
c. Only for loop prints the correct string length
d. Compile error in the program
Hide Answer
Explanation:
1. Output: 10
2. 11
In while loop the incorrect string length is printed because while loop variable 'i' get
incremented after checking for '\0', hence giving 1 more than the length of string.
Hide Answer
Explanation:
No, because continue statement can work only with loops in C-programming and not
with switch.
10) For printing the value of a and b given below, which printf()
statement will you use?
1. #include<stdio.h>
2. main()
3. float a=3.14;
4. double b=3.14;
a. printf("%Lf %f", a, b);
b. printf("%Lf %Lf", a, b);
c. printf("%f %Lf", a, b);
d. printf("%f %lf", a, b);
Hide Answer
Explanation:
Therefore for printing the value of a and b the syntax of printf statement is printf("%f
%lf", a, b);
a. 1, 3 and 4
b. 1, 2, 3 and 4
c. 2 , 3and 4
d. 1 and 4
Hide Answer
Explanation:
Nested if-else statement is allowed in C-program we can use if-else statement within if or
else statement.
Multiple statements in if or else block are allowed because we can execute multiple
statements against true value of if or else condition by placing the statements within { ?.. }.
Mostly if-else statement can be replaced by ternary operator but there are some exceptions
also in which if-else statement cannot be replaced by ternary operator.
Hide Answer
Explanation:
On compiling the program compiler will report an error "constant expression required" in the
line case P: because variable name is not allowed to be used with case statements.
The case statements only accept constant expression. Therefore the Error: Constant
expression required at line case P: is occur.
Explanation:
In switch statement constant expression are allowed therefore in case 1*2+4 statement it
will give no error.
Hide Answer
Explanation:
The basic C compiler used is 16 bit compiler, below are the size of their data types:
Hide Answer
Explanation:
Yes, char variable is allowed to store either a Unicode character or an ASCII character
because encoding of character data type is done in Unicode or ASCII format.
16) Which of the following statements are correct about below C-
program?
1. #include<stdio.h>
2. int main()
3. {
4. int x = 100, y = 100%80, j;
5. for(j=1; j<10; j++)
6. if(x != y);
7. printf("x = %d y = %d\n", x, y);
8. return 0;
9. }
1. The program produce the output x=100 y=20
2. The printf() function run for 10 times
3. The semi colon(;) after the if(x!=y) will not produce any error
4. The program will produce no output
a. 2
b. 1,3
c. 3,4
d. 4
Hide Answer
Explanation:
The statement 1 is true because x=100 and y=20 is the output of a program.
The statement 2 is false because printf() function is not inside for loop. Therefore printf
statement only runs for 1 time.
The statement 3 is true because the semicolon is used for terminating a conditional
statement. Therefore if(x!=y); is allowed in C.
The statement 4 is false because the program is producing output x=100 and y=20.
a. 1
b. 1, 2, 3
c. 2, 3, 4
d. 1, 2, 4
Hide Answer
Explanation:
For loop is used if we want statements in loop get executed at least once. Therefore for loop
works slower than a while loop i.e. statement 3 is incorrect.
Hide Answer
Explanation:
In for loop expression i.e. for(i<=5 && i>=-1; ++i; i>0) the expression i<=5 && i>=-1
is the loop condition. Expression ++i increment the expression.
In given for loop condition the loop start from 1and it gets executed till the limit of integer
i.e. 65535.
Hide Answer
Explanation:
In switch statemen,t the cases must be either constant expression or an integer constant.
Hide Answer
Explanation:
A do-while allows body of the loop to get executed before testing the condition. Therefore to
begin with, value of a, i.e. 5, gets printed, and then the control reaches the statement a=-
1.
Since -1 is not greater than 0, so the condition fails and the loop is terminated at the value
of a=5.
C Functions Test 1
Hide Answer
Explanation:
The strcmp() is a built-in function available in "string.h" header file. It is used for comparing
the two strings. It returns 0 if both are same strings. It returns positive value greater than 0
if first string is greater than second string, otherwise it returns negative value.
2) What is passed when we pass an array as a function
argument?
a. Base address of an array
b. Address of the last element of array
c. First value of elements in array
d. All value of element in array
Hide Answer
Explanation:
On passing the name of array as function argument; the name contain the base address of
an array and base address is updated inside a main function.
Hide Answer
Explanation:
Hide Answer
The correct option is (c).
Explanation:
realloc() is a built in library function for adjusting the dynamic memory size. malloc() and
calloc() allocates the memory but don't resize. There is no built in function with a name
resize().
Hide Answer
Explanation:
In C language, the return function stops the execution of function and returns a value to
calling function. Execution is begins in a calling function by instantly following the call.
Hide Answer
Explanation:
The function ultoa() is used for converting an unsigned long integer to a string.
7) What is the output of below C program?
1.
2. #include<stdio.h>
3. int function1(int);
4.
5. int main()
6. {
7. int k=30;
8. k = function1(k=function1(k=function1(k)));
9. printf("k=%d\n", k);
10. return 0;
11. }
12. int function1(int k)
13. {
14. k++;
15. return k;
16. }
a. k=30
b. k=31
c. k=32
d. k=33
Hide Answer
Explanation:
Step 1: int k=30; The variable k is declared as an integer type and initialized to 30.
Hide Answer
Explanation:
Using "flush()" function we can flush any buffered output associated with a filename, which
is either a shell command for redirecting output or a file opened for writing.
For example:
1.
2. fflush (FilePointer);
3. fflush (NULL); //It flushes all streams
Hide Answer
Explanation:
C library function strcmp() compares the two strings with each other and the value is return
accordingly.
1.
2. int strcmp (const char *str1, const char *str2)
Comparison occurs between a first string (str1) with a second string (str2).
On comparing the two string, the values return by a function strcmp() are:
Hide Answer
Explanation:
Function that disconnects the stream from a file pointer is fclose(), it flushes the buffers
associated with a stream and disconnects the stream from a file pointer.
11) If the integer data type (int) is 2 bytes wide, what is the output
of below program?
1. #include <stdio.h>
2. void fun(char**);
3.
4. int main()
5. {
6. char *argmntv[] = {"gh", "ef", "cd", "ab"};
7. fun(argmntv);
8. return 0;
9. }
10. void fun(char **x)
11. {
12. char *y;
13. y= (x+= sizeof(int))[-1];
14. printf("%s\n", y);
15. }
a. gh
b. ab
c. ef
d. cd
Hide Answer
Explanation:
The output of the above program will be ef in Windows (Turbo C) and ab in Linux (GCC).
Since C is a machine dependent language therefore sizeof(int) may return different values
in different operating system.
The given size of int is 2 bytes therefore program output is based on the Windows (Turbo C)
compiler. Therefore the output of program is ef.
Hide Answer
Explanation:
The void f() function is not visible to the compiler while going through main() function.
Hence we need to declare this prototype void f(); before the main() function. This kind of
error is not occurring in modern compiler.
Therefore on compiling the above program it give Error: Not allowed assignment.
Hide Answer
Explanation:
In printf statement i.e. printf("%p\n", main()); This statement calls the main() function and
then it repeats infinitely, until the stack is overflow.
Hide Answer
Explanation:
A function can be called either using call by reference or call by value. Therefore the above
statement is true.
For Example:
Call by reference meansc=sub(&x, &y); here the address of x and y are passed.
Call by value means c= sub(x, y); here the value of x and y are passed.
Show Answer
Explanation:
There is an error in the line 16 i.ea>=45 ? return(*y): return(*z); we are not allowed to
use return keyword in the ternary operator
Hide Answer
Explanation:
Step 3: while(j) The value of j is not initialized so the while condition is failed. Therefore it
does not execute the while block.
18) The C library function rewind() is used for re-position the file
pointer at the beginning of the file.
a. True
b. False
Hide Answer
Explanation:
In C, rewind function reposition the file position at the beginning of the file of given stream.
This function also erases the error and end-of-file indicators for stream.
Hide Answer
Explanation:
void *calloc(size_h nitems, size_h size): Function calloc() requires the double argument.
void *malloc(size_h size) : Function malloc() requires the single argument.
For supporting the function- malloc() and calloc() stdlib.h header file is required.
Hide Answer
Explanation:
Macro can be executed faster with no overhead of context switch because the code of macro
gets expanded at the line of call.
C Array Test 1
Hide Answer
Explanation:
In C language when we pass an array as a function argument, then the Base address of
the array will be passed.
Hide Answer
Explanation:
In the program we are comparing the base address of 'x' and 'y' and they are not same.
Hide Answer
Explanation:
The strlen(x) function is used for finding the length of string 'x'. In program the length of
string is count of character upto '\0'. Hence the string length output is 2.
The sizeof(x) function is used for finding the size of string 'x'. In program sizeof() returns
the size of the complete array. Hence the size of array output is 9.
Hide Answer
Explanation:
Using the standard library function malloc() and treat it as an array. The value of array is
same as pointer to a block of memory.
a. 2
b. 2,3
c. 1,4
d. 2,4
Hide Answer
Explanation:
1. The expression num[2] represents the second element in array. This statement is
false, because it represents the third element of the array.
2. The declaration of num[SIZE] is allowed if SIZE is a macro. This statement is true,
because MACRO is used for replacing the symbol size with given value.
3. The array of int num[20]; can store 20 elements. This statement is true
4. It is necessary to initialize array at the time of declaration. This statement is false
Hide Answer
Explanation:
Hide Answer
The Square parenthesis signifies an array at declaration and the type is char *. So it is an
array of character pointer.
Hide Answer
Explanation:
In program 'a' refers to constant address and the constant address variable is not allowed to
be incremented.
Hide Answer
Explanation:
The statement int num[5]; specifies the size of array and num[5]=20; specifies the
particular element (6th element) of the array.
Therefore in first statement 5 specifies an array size, whereas in second element it specifies
a particular element of an array.
a. 1, 4
b. 4
c. 1
d. 1, 3
Hide Answer
Explanation:
The statement 1 and 4 does not yield the base address of an array. While the printf() and
scanf() yields the base address of an array.
Hide Answer
Explanation:
In program the statement int arr[size]; produces an error, because we cannot initialize the
size of array dynamically. Constant expression is required for initialize the size of array. For
Example: int arr[20];
Therefore the code is erroneous since the statement declaring an array is invalid.
12) Are the expression &arr and arr different for an array of 15
integers?
a. Yes
b. No
Hide Answer
Explanation:
Yes, both mean two different things. 'arr' gives the address of first int, whereas the '&arr'
gives the address of array of ints.
Therefore the expression '&arr' and 'arr' are different for an array of 15 integers.
Hide Answer
Explanation:
No, both the declarations are same. It is a prototype for function fun() that accepts one
integer array as parameter and an integer value is return.
Hide Answer
Explanation:
Step 1: int arr[2]={20}; The variable arr[2] is declared as an integer array with size of '3'
and it's first element is initialized with value '20'(means arr[0]=20)
Step 2: printf("%d\n", 0[arr]); It prints the first element value of variable 'arr'.
15) What will be the output of the program if an array begins with
address 65486?
1. #include<stdio.h>
2. int main()
3. {
4. int arr[] = {10, 11, 12, 15, 23};
5. printf("%u, %u\n", arr, &arr);
6. return 0;
7. }
a. 65486, 65486
b. 65486, 65490
c. 65486, 65487
d. 65486, 65488
Hide Answer
Explanation:
Step 1: int arr[] = {10, 11, 12, 15, 23}; The variable 'arr' is declared as an integer array
and initialized.
Step 2: printf("%u, %u\n", arr, &arr); Here, the base address of the array is 65486.
Hence the arr, &arr is pointing towards the base address of the array arr.
Hide Answer
Explanation:
17) The return keyword is used for transfer control from a function
back to the calling function.
a. Yes
b. No
Hide Answer
Explanation:
In C, the return function stops the execution of function and returns the control with value
to the calling function. Execution is begins in calling function by instantly following the call.
Hide Answer
Explanation:
The two possible methods of accessing structure elements using pointer is by using * or ->
(arrow operator).
Hide Answer
Explanation:
In the program invalid syntax is used for initializing the array. Therefore compile error
occurs in the output of a program.
20) Find out whether both the loops in a program prints the
correct string length?
1. #include<stdio.h>
2. main()
3. {
4. int j;
5. char s[] = "javaTpoint";
6. for(j=0; s[j]; ++j);
7. printf("%d \n", j);
8.
9. j=0;
10. while(s[j++]);
11. printf("%d ", j);
12. }
a. Yes, both the loops prints the correct string length
b. Only while loop prints the correct string length
c. Only for loop prints the correct string length
d. Compile error in the program
Hide Answer
Explanation:
1. Output: 10
2. 11
In while loop the incorrect string length is printed because while loop variable 'i' get
incremented after checking for '\0', hence giving 1 more than the length of string.
next →← prev
C Pointers Test 1
Hide Answer
Explanation:
For a structure, Arrow ( ->) is used for access the data using pointer variable and Dot(.) operator can b
accessing the data using normal structure variable.
2) For the array element a[i][j][k][2], determine the equivalent pointer expre
a. *(*(*(*(a+i)+j)+k)+2)
b. *( ((a+m)+n+o+p)
c. ((((a+m)+n)+o)+p)
d. *( (((a+m)+n)+o+p)
Hide Answer
Explanation:
Hide Answer
++*ptr increments the value pointed by ptr and*ptr++ increments the pointer not the value.
Hide Answer
Explanation:
The below code is a prototype of malloc() function, here ptr indicates the pointer.
In below code, "*p" is a pointer of data type char and malloc() function is used for allocating the memor
1.
2. char *p = (char*)malloc(100);
Hide Answer
The correct option is (d).
Explanation:
The size of int and unsigned data type is same therefore there is no problem in a C statement:
Hide Answer
Explanation:
If we execute and compile this program in Linux platform using GCC Compiler, then it will
give output "Hello ello llo lo o".
7) How many bytes are occupied by far, near and huge pointers in
DOS (Disk Operating System)?
a. near=4 far=8 huge=8
b. near=4 far=4 huge=8
c. near=2 far=4 huge=4
d. near=2 far=4 huge=8
Hide Answer
Explanation:
Under DOS the value of near, far and huge pointer is:
o near=2
o far=4
o huge=4
Hide Answer
Explanation:
In normal pointer assignment, when function (fun()) is called it's received as (j), so
whatever operation performed on j will be returned at i in main.
1. &i=**j
2. i=*j
3. In function fun(),
4. *j=&b
5. So, i=&b
Therefore the address of (b) get stored in (i) when we use statement *j=&b.
Hide Answer
The correct option is (b).
Explanation:
There is no error on compilation of the program in GCC under Linux and Turbo C under
DOS.
10) Are the three declarations char **ball, char *ball[], and char
ball[][] same?
a. True
b. False
Hide Answer
Explanation:
No, the three declarations char **ball, char *ball[], and char ball[][] are different.
Hide Answer
Explanation:
In some cases it is necessary to give command line values to the C programming for
executing the particular code when the code of program is controlled from outside. This
command line values are known as command line arguments. The command line arguments
are handled by main() function.
Here, argv[] refers to the pointer array which points to each argument passed to the
program and argc is a number of argument passed.
Hide Answer
Explanation:
In given C statement the size of int and unsigned is same. Hence, there is no problem in
allocating the memory.
Explanation:
Every type of pointer variable occupies the same amount of memory irrespective of any
data type.
Therefore both the printf() statement will print the same value.
Hide Answer
Explanation:
First print statement i.e. printf("%s ", a); used for printing the value stored in pointer a.
Hence the C++ is printed in output.
Hence, the second print statement i.e. printf("%s ", a); prints the ++ in output.
Hide Answer
Explanation:
In the given statement "pf" is a pointer as well as it holds some function reference.
Hide Answer
Explanation:
In the program x points the NULL address. It is invalid to access the NULL address hence
the program gives Runtime error.
Hide Answer
Explanation:
Hide Answer
Explanation:
Hide Answer
Explanation:
In program 'i' is the variable contain pointer. So it is pointer variable and points toward an
integer type in memory location. Therefore 'i' is a pointer to an int.
Now the address of 'j' is assigned to the 'i' pointer, i.e. address of 'j' store to 'i' location.
Therefore the 'i' is a pointer to an int and it stores the address of 'j'.
Hide Answer
Explanation:
In program while loop continues until *s is not equal to '\0'. Inside loop character is fetched
first and address is incremented later.
Therefore the print statement i.e. printf("%c", *p++); will print the Xyz in output.
C String Test 1
Hide Answer
Explanation:
The function gets() is used for collecting a string of characters terminated by new line from
the standard input stream stdin.
Show Answer
Hide Answer
Explanation:
C library function strcmp() compares the two strings with each other and the value is return
accordingly.
1.
2. int strcmp (const char *str1, const char *str2)
Comparison occurs between a first string (str1) with a second string (str2).
On comparing the two string, the values return by a function strcmp() are:
Hide Answer
The strcmp() is a built-in function available in "string.h" header file. It is used for comparing
the two strings. It returns 0 if both are same strings. It returns positive value greater than 0
if first string is greater than second string, otherwise it returns negative value.
Hide Answer
Explanation:
Step 1: char a[] = "%d\n"; The variable 'a' is declared as an array of characters and
initialized with string "%d".
Step 2: a[1] = 'b'; Here, we overwrite the second element of array ?a? by 'b'. Hence the
array ?a? becomes "%c".
Therefore it will print the ASCII value of 65. Hence the output is 'A'.
Hide Answer
Explanation:
a. 1, 4
b. 1, 2, 3
c. 1, 2, 4
d. 2, 3, 4
Hide Answer
Explanation:
Clearly the statement 1, 2 and 4 are correct about the string but the statement 3 is
incorrect because we can use pointer on strings.
Hide Answer
Explanation:
Yes, for arr[2] and ptr[2] both the statements will prints the same character 'v'.
Hide Answer
The correct option is (a).
Explanation:
Output:
1.
2. Enter the string: javaTpoint
3. JAVATPOINT
10) Determine the wrong file opening mode from the following.
a. w
b. a
c. x
d. r
Hide Answer
Explanation:
File opening mode "x" is incorrect because there is no such mode exists for file opening
operation in C language.
11) Function fopen() with the mode "r+" used to open a file for
_______
a. reading and adding new content
b. reading and writing
c. it works only for directory
d. only for reading
Hide Answer
Explanation:
Function fopen() opens the file and mode "r+" used for checking the file should exist and
opens for both reading writing operation.
Therefore in file handling reading and writing operation is performed by function fopen()
with the mode "r+".
12) Which is used in mode string for opening the file in binary
mode?
a. a
b. B
c. b
d. bin
Hide Answer
Explanation:
For opening the file in binary mode the alphabet 'b' is used in mode string. To perform
unformatted data I/O a file is opened in binary mode.
Hide Answer
Explanation:
On comparing the two string, the values return by a function strcmp() are:
The strcmp() return an int value and from the given statement only statement (a) is correct
i.e. strcmp(s1, s2) returns 0 if s1==s2
Hide Answer
Explanation:
Explanation:
Hide Answer
Explanation:
The strstr() function returns pointer to the first occurrence of the matched string in the
given string. It is used to return substring from first match till the last character.
Syntax:
string: It represents the full string from where substring will be searched.
Hide Answer
Explanation:
The strlen(x) function is used for finding the length of string 'x'. In program the length of
string is count of character upto '\0'. Hence the string length output is 2.
The sizeof(x) function is used for finding the size of string 'x'. In program sizeof() returns
the size of the complete array. Hence the size of array output is 9.
18) If the size of pointer is 4 bytes then what will be the output of
below program?
1. #include<stdio.h>
2. int main()
3. {
4. char *stri[] = {"Java", "C", "Android", "Embedded", "JS"};
5. printf("%d, %d", sizeof(stri), strlen(stri[0]));
6. return 0;
7. }
a. 22, 4
b. 20, 4
c. 20, 5
d. 25,4
Hide Answer
Explanation:
Step 1: char *stri[] = {"Java", "C", "Android", "Embedded", "JS"}; The variable stri is
declaraed as a pointer to the array of 5 strings.
Hide Answer
Explanation:
The statement printf("%c\n", "javatpoint"[5]); prints the 6th character of the string
"javatpoint".
Hide Answer
Explanation:
The %u format specifier tells the compiler to print the memory address of the "Welcome".
The %s format specifier tells the compiler to print the string "Programming".
Explanation:
A structure, enumeration and union all of them can be helpful in defining a new data types
in C language.
It is used for creating new data types that holds all kinds of data type like int, char, float,
array inside a user defined data type. So user can use new values and logic of operation in
simple manner.
Hide Answer
Explanation:
The built in function free(var-name) is used for free or clear the memory space. If we use
free() the referred memory location can be released for the future use or other operations.
Therefore the free(var-name) is used for clear the allocated memory in a C program.
Hide Answer
Explanation:
In address mapping or allocation of structure, the program takes union as a one data type
in it.
Hide Answer
Explanation:
The union variable share the common memory for all its elements 'a' gets 'A' whose ASCII
value is 65.
The statement printf("%d", var.a); is used for printing the value 65 in output.
Hide Answer
Explanation:
No, because the elements of union and structure are always accessed using dot(.) operator.
6) What will be the output of the below program?
1. #include<stdio.h>
2. int main()
3. {
4. union b
5. {
6. int j;
7. char ch[2];
8. };
9. union b un;
10. un.ch[0]=3;
11. un.ch[1]=2;
12. printf("%d, %d, %d\n", un.ch[0], un.ch[1], un.j);
13. return 0;
14. }
a. 3, 2, 5
b. 515, 515, 4
c. 3, 2, 515
d. 515, 2, 3
Hide Answer
Explanation:
The statements un.ch[0]=3; un.ch[1]=2; store the data in memory as shown below:
Hide Answer
Explanation:
Increment and decrement operations are not allowed to be performed in user defined data
type.
Since enum is a user defined data type, no operations can be performed on user-defined
data types.
Therefore ++ or -- logical operations cannot be done on enum value and the program will
return compile error in the output on using this operations in enum data type.
Hide Answer
The structure employ contains a member 'e' of a same data type i.e. struct employ.
In this stage the compiler does not know the size of structure.
Hide Answer
Explanation:
We have to use strcpy(char *dest, const char *source) function for assigning a string
For example: strcpy(e.name, "Nakul");
Hide Answer
Explanation:
In enum data type sequence always start with 0. If the value is assigned then sequence
continues from the assigned value.
Hide Answer
Explanation:
Union is special data type used in C programming it allows to store different data types in
the same memory location.
All the element of union share the common memory and union size is biggest element size.
a. 4 4 garbage value
b. 4 4 0
c. 4 4 4
d. Compile error
Hide Answer
Explanation:
The two possible methods of accessing structure elements using pointer is by using * or ->
(arrow operator).
Hide Answer
Explanation:
A compiler may leave the holes in structure by padding in the first char in a structure with
another byte for ensuring that the integer is stored at a location.
Also, there is 2 extra bytes after the integer to ensure that long integer is stored at
specified address which is multiple of 4.
Hide Answer
Explanation:
In C-language switch/casev statement is defined by the language specification to use
an int value therefore we cannot use a float value in switch/case statement.
Hide Answer
Explanation:
True, C language allows the use of nested union. Therefore we can use the union inside a
union in C program.
Hide Answer
Explanation:
Hide Answer
Explanation:
1. #include<stdio.h>
2. union Pointer
3. {
4. unsigned int a:4;
5. unsigned int b:4;
6. int res;
7. };
8. int main()
9. {
10. union Pointer pt;
11. pt.a = 2;
12. pt.b = 6;
13. pt.res = pt.b;
14. printf("\n The value of res is: %d" , pt.res);
15. return 0;
16. }
17. // Output: The value of res is: 6
Explanation:
All the union elements may have different sizes but they share the common space of
memory.
19) If the below structure is used for writing into a file using
fwrite(), can fread() read it back successfully?
1. struct employ
2. {
3. char *p;
4. int age;
5. };
6. struct employ e={"javaTpoint", 25};
7. FILE *fp;
8. fwrite(&e, sizeof(e), 1, fp);
a. Yes
b. No
Hide Answer
Explanation:
No, because the structure in a program contain a char pointer while writing the structure to
the disk using fwrite() only the data stored in pointer 'n' will get written. Hence
the fread() fails to read the data stored in pointer.
Hide Answer
Explanation:
Since the C language is machine or compiler dependent language. In Turbo C(DOS) the size
of integer data type is 2.
Therefore the statement printf("%d \n", sizeof(bit)); prints the value 2 in output.
C Preprocessor Test 1
Hide Answer
The correct option is (c).
Explanation:
During preprocessing stage the line #include<stdio.h> with the system header file of that
name gets replaced by the contents of file stdio.h.
Therefore the entire text of the file 'stdio.h' replaces with #include directive.
Hide Answer
Explanation:
True, the directive #undef can be used only with a macro that has been #define earlier in
a program.
Hide Answer
Explanation:
True, the C macros like #ifdef...#elif?#endif are used for performing conditional operation
in C program.
1. #if <constant-expression>
2. #elif <constant-expression>
3. #endif
Hide Answer
Explanation:
The macro statement SWAP(x, y) int t; t=x, x=y, y=t; swaps the value of given two
variable.
Step 1: int x=10, y=20; The variable x and y are declared as an integer type and
initialized to 10, 20 respectively.
Step 2: SWAP(x, y);. Here the macro is substituted and it swaps the value to variable x
and y.
Hide Answer
Explanation:
Hide Answer
Explanation:
While defining the macro DEF, it is not compulsory to provide a expansion to the macro
statement because in a program we are not using the value of macro expansion.
Hide Answer
Explanation:
When the preprocessor sends the program for compilation IT, HRA and DA have been
replaced by 0.1, 0.2 and 0.3 respectively. With the bas_sal set to 1000, the net salary is
calculated as:
1. net_sal=bas_sal*(1+0.2+0.3-0.1);
The statement printf("Gross salary=%f\n", net_sal); prints the result. Therefore the
output of Output:
Gross salary=1400
8) It is necessary that header files must have the .h extension?
a. Yes
b. No
Hide Answer
Explanation:
No, the header files may have any extension. It is not necessary that header file must have
.h extension.
Show Answer
Hide Answer
Explanation:
Macro statement can be executed faster with no overhead of context switch because the
code of macro gets expanded at the line of call.
Hide Answer
Explanation:
There is no such operator called $. The second and third operator are used for stringize and
token pasting operators respectively.
Therefore the operator '\' is used for continue the definition of macro in the next line.
Hide Answer
Explanation:
There is no such macro defined with the name __C++__, but the __cplusplus__ is
predefined macro as per ANSI C specification.
Hide Answer
Explanation:
The conditional macro statement #if must have an #endif statement. In the program there
is no #endif statement used.
Therefore the program returns an Error: unexpected end of file because there is no
matching #endif.
a. 1, 2, 4
b. 1, 3, 4
c. 1, 4
d. 1, 2, 3, 4
Hide Answer
Explanation:
The macro statement #undef undefined the previously declared macro symbol.
The macro statement #if #ifdef #elif are called conditional macros.
Hence all the given statements are correct macro preprocessor directives in C language.
Hide Answer
Explanation:
During preprocessing, the occurrence of MEAN is replaced with their expansion, then send
to compiler and program is executed as below:
1. #include <stdio.h>
2. int main()
3. {
4. int p=1, q=2, r=3, s=4, t=5, mn;
5. m=(p+q+r+s+t)/5;
6. printf("Mean of 5 numbers=%d\n",mn);
7. return 0;
8. }
Hide Answer
Explanation:
During preprocessing, the macro MYFILE gets replaced with <stdio.h>, then program is
compiled and executed as shown below:
1. int main()
2. {
3. printf("Hello\n");
4. printf("Welcome to javatpoint\n");
5. return 0;
6. }
7. #include <stdio.h>
Hello
Welcome to javatpoint
Hide Answer
Explanation:
In GCC compilers and Turbo C the compiler would take care of these problems and it
generates no error. In other compilers the error may occur.
Unless the header file has taken care for ensure that if already included then it doesn't get
included again.
Therefore an error in a program due to use of header file twice in a program is compiler
dependent.
18) The preprocessor can trap simple error like nested comments,
mismatch of braces or missing declarations.
a. True
b. False
Hide Answer
Explanation:
The statement is false because the preprocessor cannot trap the errors; it only replaces the
macro with the given expression.
Hide Answer
The statement is false because the preprocessor directive is not compulsory in any C
program. We can also develop a program in C language without using any preprocessor
directive.
Hide Answer
Explanation:
The macro MAX(x, y) (x > y ? x : y) returns the biggest value of the given two numbers.
=> a = (4 > 6 ? 4 : 6)
=> a = 6