Loading Test...
Instruction:
Total number of questions : 20 .
Time alloted : 20 minutes.
Each question carry 1 mark, no negative marks.
1.
Which statement will you add in the following program to work it correctly?
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}
Answer: Option B
Explanation:
math.h is a header file in the standard library of C programming language designed for basic mathematical operations.
Declaration syntax : double log(double);
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum
2.
What will be the output of the program?
#include<stdio.h>
#define PRINT(i) printf("%d,",i)
int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}
A.
2, 3, 4,
B.
2, 2, 2,
C.
3, 3, 3,
D.
4, 4, 4,
Answer: Option A
Explanation:
The macro PRINT(i) print("%d,", i); prints the given variable value in an integer format.
Step 1 : int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to 2, 3, 4 respectively.
Step 2 : PRINT(x); becomes printf("%d,",x) . Hence it prints '2'.
Step 3 : PRINT(y); becomes printf("%d,",y) . Hence it prints '3'.
Step 4 : PRINT(z); becomes printf("%d,",z) . Hence it prints '4'.
Hence the output of the program is 2, 3, 4.
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
3.
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include<stdio.h>
int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}
4.
Which of the following statements correct about k used in the below statement?char ****k;
5.
What does the following declaration mean?
int (*ptr)[10];
6.
What will be the output of the program in Turbo-C ?
#include<stdio.h>
int main()
{
int arr[5], i=-1, z;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
A.
1, 2, 3, 4, 5,
B.
-1, 0, 1, 2, 3, 4
C.
0, 1, 2, 3, 4,
D.
0, -1, -2, -3, -4,
Answer: Option C
Explanation:
Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (under DOS) output.
Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum
7.
What will be the output of the program in 16-bit platform (Turbo C under DOS) ?
#include<stdio.h>
int main()
{
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
return 0;
}
Answer: Option B
Explanation:
Step 1 :
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
The sizeof function returns the size of the given expression.
sizeof(3.0f) is a floating point constant. The size of float is 4 bytes
sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes
sizeof(3.0) is a double constant. The size of double is 8 bytes
Hence the output of the program is 4,2,8
Note: The above program may produce different output in other platform due to the platform dependency of C compiler.
In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum
8.
Point out the error in the program?
#include<stdio.h>
int main()
{
struct emp
{
char name[20];
float sal;
};
struct emp e[10];
int i;
for(i=0; i<=9; i++)
scanf("%s %f", e[i].name, &e[i].sal);
return 0;
}
Answer: Option B
Explanation:
At run time it will show an error then program will be terminated.
Sample output: Turbo C (Windows)
c:\>myprogram
Sample
12.123
scanf : floating point formats not linked
Abnormal program termination
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum
9.
A structure can contain similar or dissimilar elements
10.
A pointer union CANNOT be created
11.
What will be the output of the program if value 25 given to scanf() ?
#include<stdio.h>
int main()
{
int i;
printf("%d\n", scanf("%d", &i));
return 0;
}
Answer: Option C
Explanation:
The scanf function returns the number of input is given.
printf("%d\n", scanf("%d", &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is '1'.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
12.
Point out the error in the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return 0;
}
Answer: Option C
Explanation:
This program tries to open the file trial.txt in read mode. If file not exists or unable to read it prints "Unable to open file" and then terminate the program.
If file exists, it simply close the file and then terminates the program.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
13.
What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
cmd> sample Good Morning
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
14.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%c", *++argv[2] );
return 0;
}
15.
Even if integer/float arguments are supplied at command prompt they are treated as strings.
16.
If the different command line arguments are supplied at different times would the output of the following program change?
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%d\n", argv[argc]);
return 0;
}
17.
What will be the output of the program?
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e;
e.err=1;
printf("%d\n", e.err);
return 0;
}
18.
What will be the output of the program?
#include<stdio.h>
int main()
{
const int i=0;
printf("%d\n", i++);
return 0;
}
Answer: Option D
Explanation:
This program will show an error "Cannot modify a const object".
Step 1 : const int i=0; The constant variable 'i' is declared as an integer and initialized with value of '0'(zero).
Step 2 : printf("%d\n", i++); Here the variable 'i' is increemented by 1(one). This will create an error "Cannot modify a const object".
Because, we cannot modify a const variable.
Learn more problems on : Const
Discuss about this problem : Discuss in Forum
19.
Which standard library function will you use to find the last occurance of a character in a string in C?
Answer: Option D
Explanation:
strrchr() returns a pointer to the last occurrence of character in a string.
Example :
#include <stdio.h>
#include <string.h>
int main()
{
char str[30] = "12345678910111213";
printf("The last position of '2' is %d.\n",
strrchr(str, '2') - str);
return 0;
}
Output : The last position of '2' is 14.
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum
20.
Data written into a file using fwrite() can be read back using fscanf()
Answer: Option B
Explanation:
fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.
Learn more problems on : Library Functions
Discuss about this problem : Discuss in Forum
Submit your test now to view the Results and Statistics with answer explanation.
Note:
Click the 'Submit Test' button given in the bottom of this page to Submit your answers.
Test will be submitted automatically if the time expired.
Don't refresh the page.
Marks : [XX/XX]
Total number of questions
:
[TQ]
Number of answered questions
:
[AQ]
Number of unanswered questions
:
[UQ]