1-
|
How will you free the allocated memory ?
|
|
A -
|
remove(var-name);
|
|
B -
|
free(var-name);
|
|
C -
|
delete(var-name);
|
|
D -
|
dalloc(var-name);
|
2-
|
In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?
|
|
A -
|
"I am a boy\r\n\0"
|
|
B -
|
"I am a boy\r\0"
|
|
C -
|
"I am a boy\n\0"
|
|
D -
|
"I am a boy"
|
3-
|
Which files will get closed through the fclose() in the following program?
#include<stdio.h>
int main()
{
FILE *fs, *ft, *fp;
fp = fopen("A.C", "r");
fs = fopen("B.C", "r");
ft = fopen("C.C", "r");
fclose(fp, fs, ft);
return 0;
}
|
|
A -
|
"A.C" "B.C" "C.C"
|
|
B -
|
"B.C" "C.C"
|
|
C -
|
"A.C"
|
|
D -
|
Error in fclose()
|
4-
|
If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?
#include<stdio.h>
int main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c[0] = getc(fs);
fseek(fs, 0, SEEK_END);
fseek(fs, -3L, SEEK_CUR);
fgets(c, 5, fs);
puts(c);
return 0;
}
|
|
A -
|
friend
|
|
B -
|
frien
|
|
C -
|
end
|
|
D -
|
Error in fseek();
|
5-
|
According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?
|
|
A -
|
int main(int argc, char *argv[])
|
|
B -
|
int main(argc, argv) int argc; char *argv;
|
|
C -
|
int main() { int argc; char *argv; }
|
|
D -
|
None of above
|
6-
|
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)
{
printf("%s\n", *++argv);
return 0;
}
|
|
A -
|
myprog
|
|
B -
|
one
|
|
C -
|
two
|
|
D -
|
three
|
7-
|
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p, i, j;
/* Add statement here */
for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
p[i*4+j] = i;
printf("%d", p[i*4+j]);
}
}
return 0;
}
|
|
A -
|
p = (int*) malloc(3, 4);
|
|
B -
|
p = (int*) malloc(3*sizeof(int));
|
|
C -
|
p = malloc(3*4*sizeof(int));
|
|
D -
|
p = (int*) malloc(3*4*sizeof(int));
|
8-
|
malloc() allocates memory from the heap and not from the stack.
|
|
A -
|
True
|
|
B -
|
False
|
9-
|
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
int fun1();
int fun2();
int main()
{
int (*p1)();
int (*p2)();
p1 = fun1;
p2 = fun2;
display("IndiaBIX", p1, p2);
return 0;
}
void display(char *s, ...)
{
int (*pp1)();
int (*pp2)();
va_list ptr;
va_start(ptr, s);
pp1 = va_arg(ptr, int(*)());
(*pp1)();
pp2 = va_arg(ptr, int(*)());
(*pp2)();
}
int fun1()
{
printf("Hello");
}
int fun2()
{
printf("Hi");
}
|
|
A -
|
Error: invalid function display() call
|
|
B -
|
Error: invalid va_start(ptr, s);
|
|
C -
|
Error: va_arg cannot extract function pointer from variable argument list.
|
|
D -
|
Error: Rvalue required for t
|
10-
|
What do the following declaration signify?
int (*ptr)[30];
|
|
A -
|
ptr is a pointer to an array of 30 integer pointers.
|
|
B -
|
ptr is a array of 30 integer function pointer.
|
|
C -
|
ptr is a array of 30 integer pointers.
|
|
D -
|
ptr is a array 30 pointers.
|