1.
|
We want to round off x, a float,
to an int value, The correct way to do is
|
||||||||||||||||
Answer: Option A
Explanation:
Rounding off a value means
replacing it by a nearest value that is approximately equal or smaller or
greater to the given number.
y = (int)(x + 0.5); here x is any float value. To roundoff, we have to
typecast the value of x by using (int)
Example:
#include <stdio.h>
int
main ()
{
float x = 3.6;
int y = (int)(x + 0.5);
printf ("Result = %d\n", y );
return 0;
}
Output:
Result = 4. |
2.
|
Every function must return a value
|
||||||||
Answer: Option B
Explanation:
No, If a function return type is
declared as void it cannot return any value.
|
3.
|
What will be the output of the
program ?
#include<stdio.h>
int
main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
|
||||||||||||||||
Answer: Option C
Explanation:
The program will generate infinite
loop. When an EOF is encountered fgetc() returns EOF. Instead of
checking the condition for EOF we have checked it for NULL. so the program
will generate infinite loop.
|
4.
|
What will be the output of the
program?
#include<stdio.h>
int
main()
{
char str[]="C-program";
int a = 5;
printf(a >10?"Ps\n":"%s\n", str);
return 0;
}
|
||||||||||||||||
Answer: Option A
Explanation:
Step 1: char str[]="C-program"; here variable str
contains "C-program".
Step 2: int a = 5; here variable a contains "5". Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as
if(a
> 10)
{
printf("Ps\n");
}
else
{
printf("%s\n", str);
}
Here we are checking a > 10
means 5 > 10. Hence this condition will be failed. So it prints
variable str.
Hence the output is
"C-program".
|
5.
|
Preprocessor directive #ifdef
.. #else ... #endif is used for conditional compilation.
|
||||||||
Answer: Option A
Explanation:
True, these macros are used for
conditional operation.
#if <constant-expression>
#elif <constant-expression>
#endif
|
6.
|
Which of the following statements
correct about the below program?
#include<stdio.h>
int
main()
{
struct emp
{
char name[25];
int age;
float sal;
};
struct emp e[2];
int i=0;
for(i=0; i<2; i++)
scanf("%s
%d %f", e[i].name,
&e[i].age, &e[i].sal);
for(i=0; i<2; i++)
scanf("%s
%d %f",
e[i].name, e[i].age, e[i].sal);
return 0;
}
|
||||||||||||||||
Answer: Option C
Explanation:
Refer the explanation given for
another problem:
|
7.
|
Is there any difference int the
following declarations?
int fun(int arr[]); int fun(int arr[2]); |
||||||||
Answer: Option B
Explanation:
No, both the statements are same.
It is the prototype for the function fun() that accepts one integer
array as an parameter and returns an integer value.
|
8.
|
What will be the output of the
program?
#include<stdio.h>
int
i;
int
fun();
int
main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int
fun()
{
printf("Hi");
}
|
||||||||||||||||
Answer: Option A
Explanation:
Step 1: int i; The variable
i is declared as an integer type.
Step 1: int fun(); This
prototype tells the compiler that the function fun() does not accept
any arguments and it returns an integer value.
Step 1: while(i) The value
of i is not initialized so this while condition is failed. So, it does
not execute the while block.
Step 1: printf("Hello\n");
It prints "Hello".
Hence the output of the program is
"Hello".
|
9.
|
What will be the output of the
program?
#include<stdio.h>
int
fun(int, int);
typedef int
(*pf) (int, int);
int
proc(pf, int, int);
int
main()
{
printf("%d\n", proc(fun, 6,
6));
return 0;
}
int
fun(int a, int b)
{
return (a==b);
}
int
proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
|
||||||||||||||||
Answer: Option B
|
10.
|
What will be the output of the
program ?
#include<stdio.h>
#include<string.h>
int
main()
{
char sentence[80];
int i;
printf("Enter a line of text\n");
gets(sentence);
for(i=strlen(sentence)-1; i >=0;
i--)
putchar(sentence[i]);
return 0;
}
|
||||||||||||||||
Answer: Option B
|
11.
|
What will be the output of the program
(Turbo C in 16 bit platform DOS) ?
#include<stdio.h>
#include<string.h>
int
main()
{
char *str1 = "India";
char *str2 = "BIX";
char *str3;
str3 = strcat(str1, str2);
printf("%s %s\n", str3, str1);
return 0;
}
|
||||||||||||||||
Answer: Option B
Explanation:
It prints 'IndiaBIX IndiaBIX' in
TurboC (in 16 bit platform).
It may cause a 'segmentation fault
error' in GCC (32 bit platform).
|
12.
|
What will be the output of the
program ?
#include<stdio.h>
power(int**);
int
main()
{
int a=5, *aa; /* Address of 'a' is
1000 */
aa = &a;
a = power(&aa);
printf("%d\n", a);
return 0;
}
power(int
**ptr)
{
int b;
b = **ptr***ptr;
return (b);
}
|
||||||||||||||||
Answer: Option B
|
13.
|
What will be the output of the
program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>
int
main(int argc, char **argv)
{
int i;
for(i=1; i<=3; i++)
printf("%u\n", &argv[i]);
return 0;
}
If the first value printed by the
above program is 65517, what will be the rest of output?
|
||||||||||||||||
Answer: Option B
|
14.
|
Which of the following cannot be
checked in a switch-case statement?
|
||||||||||||||||
Answer: Option C
Explanation:
The switch/case statement
in the c language is defined by the language specification to use an int
value, so you can not use a float value.
switch(
expression )
{
case constant-expression1:
statements 1;
case constant-expression2:
statements 2;
case constant-expression3:
statements3 ;
...
...
default : statements 4;
}
The value of the 'expression'
in a switch-case statement must be an integer, char, short, long. Float and
double are not allowed.
|
15.
|
Point out the error in the
program?
#include<stdio.h>
int
main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20", SEEK_SET);
fclose(fp);
return 0;
}
|
||||||||||||||||
Answer: Option B
Explanation:
Instead of "20" use 20L
since fseek() need a long offset value.
|
16.
|
What will be the output of the
program in Turbo C (under DOS)?
#include<stdio.h>
int
main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
|
||||||||||||||||
Answer: Option B
|
17.
|
What do the following declaration
signify?
char
**argv;
|
||||||||||||||||
Answer: Option B
|
18.
|
What will be the output of the
program?
#include<stdio.h>
int
main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j || ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
|
||||||||||||||||
Answer: Option C
Explanation:
Step 1: int i=-3, j=2, k=0, m; here variable i, j, k,
m are declared as an integer type and variable i, j, k are
initialized to -3, 2, 0 respectively.
Step 2: m = ++i && ++j || ++k;
becomes m = (-2 && 3) || ++k; becomes m = TRUE || ++k;. (++k) is not executed because (-2 && 3) alone return TRUE. Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.
Step 3: printf("%d, %d, %d, %d\n", i, j, k, m);
In the previous step the value of i,j are increemented by '1'(one).
Hence the output is "-2, 3,
0, 1".
|
19.
|
By default structure variable will
be of auto storage class
|
||||||||
Answer: Option A
|
20.
|
Can we write a function that takes
a variable argument list and passes the list to another function?
|
||||||||
Answer: Option A
|
No comments:
Post a Comment