C Programming Questions
C Programming Questions
1. Which of the following statements should be used to obtain a remainder after dividing 3.14
by 2.1?
A.
B.
C.
D.
B.
C.
D.
Internal
* (asterisk)
B.
| (pipeline)
C.
- (hyphen)
D.
_ (underscore)
B.
C.
D.
None of these
6.
7.
A.
ceil(1.66)
B.
floor(1.66)
C.
roundup(1.66)
D.
roundto(1.66)
float
B.
double
C.
long double
D.
far double
2:
3:
8.
struct book
{
char name[10];
float price;
int pages;
};
A.
B.
C.
D.
Both 1 and 2
extern int i;
9.
A.
Declaration
B.
Definition
C.
Function
D.
Error
B.
C.
10.
1 and 3
D.
In the following program where is the variable a getting defined and where it is getting
declared?
#include<stdio.h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;
A.
B.
C.
D.
Defining
B.
Declaring
C.
Prototyping
D.
Calling
float, double
B.
C.
D.
use 3.14LD
B.
use 3.14L
C.
use 3.14DL
D.
use 3.14LF
3. If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000
0000 0000, what will be the output of the program (on intel 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;
}
A.
40 AC 00 00
B.
04 CA 00 00
C.
00 00 AC 40
D.
00 00 CA 04
4. Which of the following range is a valid long double (Turbo C in 16 bit DOS OS) ?
A.
3.4E-4932 to 1.1E+4932
B.
3.4E-4932 to 3.4E+4932
C.
1.1E-4932 to 1.1E+4932
D.
1.7E-4932 to 1.7E+4932
5. 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;
}
A.
#include<conio.h>
B.
#include<math.h>
C.
#include<stdlib.h>
D.
#include<dos.h>
y = (int)(x + 0.5)
B.
y = int(x + 0.5)
C.
y = (int)x + 0.5
D.
y = (int)((int)x + 0.5)
101.101110111
B.
101.011
C.
101011
D.
None of above
8. A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D,
then when this float is stored in memory in which of the following order do these bytes gets
stored?
A.
ABCD
B.
DCBA
C.
0xABCD
D.
use float(3.14f)
B.
use 3.14f
C.
use f(3.14)
D.
use (f)(3.14)
10. Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
A.
B.
C.
D.
POINTERS
1. What is (void*)0?
A.
B.
C.
Error
D.
None of above
char p = *malloc(100);
B.
C.
char *p = (char*)malloc(100);
D.
stdio.h
B.
stddef.h
C.
D.
math.h
4. How many bytes are occupied by near, far and huge pointers (DOS)?
5.
A.
B.
C.
D.
B.
&
C.
D.
->
6. What would be the equivalent pointer expression for referring the array
element a[i][j][k][l]
A.
((((a+i)+j)+k)+l)
B.
*(*(*(*(a+i)+j)+k)+l)
C.
(((a+i)+j)+k+l)
D.
((a+i)+j+k+l)
7. A pointer is
A.
B.
C.
D.
B.
&
C.
&&
D.
||
LIBRARY FUNCTIONS
1. What will the function rewind() do?
A.
B.
C.
D.
2. Input/output function prototypes and macros are defined in which header file?
A.
conio.h
B.
stdlib.h
C.
stdio.h
D.
dos.h
3. Which standard library function will you use to find the last occurance of a character in a
string in C?
A.
strnchar()
B.
strchar()
C.
strrchar()
D.
strrchr()
4. What is stderr ?
A.
standard error
B.
C.
D.
5. Does there any function exist to convert the int or float to a string?
A.
Yes
B.
B.
C.
No
D.
7. Can you use the fprintf() to display the output on the screen?
A.
Yes
B.
No
B.
C.
D.
INPUT / OUTPUT
1. In a file contains the line "I am a boy\r\n" then on reading this line into the
array strusing 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"
2. What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
A.
B.
C.
D.
None of above
B.
A structure which contains a char pointer which points to the first character of a
file.
C.
D.
4. Which of the following operations can be performed on the file "NOTES.TXT" using the
below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");
A.
Reading
B.
Writing
C.
Appending
D.
5. To print out a and b given below, which of the following printf() statement will you use?
#include<stdio.h>
float a=3.14;
double b=3.14;
A.
B.
C.
D.
6. 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.
B.
"B.C" "C.C"
C.
"A.C"
D.
Error in fclose()
7. On executing the below program what will be the contents of 'target.txt' file if the source file
contains a line "To err is human"?
#include<stdio.h>
int main()
{
int i, fss;
char ch, source[20] = "source.txt", target[20]="target.txt", t;
FILE *fs, *ft;
fs = fopen(source, "r");
ft = fopen(target, "w");
while(1)
{
ch=getc(fs);
if(ch==EOF)
break;
else
{
fseek(fs, 4L, SEEK_CUR);
fputc(ch, ft);
}
}
return 0;
}
A.
rn
B.
Trh
C.
err
D.
None of above
8. To scan a and b given below, which of the following scanf() statement will you use?
#include<stdio.h>
float a;
double b;
A.
B.
C.
D.
gets()
B.
fgets()
B.
C.
Garbage value
D.
Error in fileno()
EXPRESSIONS
1. Which of the following is the correct order of evaluation for the below
expression?
z=x+y*z/4%2-1
A.
*/%+-=
B.
=*/%+-
C.
/*%-+=
D.
*%/-+=
/+*-
B.
*-/+
C.
+-/*
D.
/*+-
B.
a>b ? c=30;
C.
D.
return (a>b)?(a:b)
4. Which of the following is the correct order if calling functions in the below
code?
a = f1(23, 14) * f2(12/4) + f3();
A.
f1, f2, f3
B.
f3, f2, f1
C.
D.
None of above
A.
1, 2
B.
1, 3
C.
2, 4
D.
1, 2, 3
B. 1234
C. 4321
D. 3214
STRINGS
1. Which of the following function sets first n characters of a string to a given character?
A.
strinit()
B.
strnset()
C.
strset()
D.
strcset()
-1
B.
C.
D.
Yes
printf("\n");
B.
echo "\\n";
C.
printf('\n');
D.
printf("\\n");
4. The library function used to find the last occurrence of a character in a string is
A.
strnstr()
B.
laststr()
C.
strrchr()
D.
strstr()
5. Which of the following function is used to find the first occurrence of a given string in
another string?
A.
strchr()
B.
strrchr()
C.
strstr()
D.
strnset()
6. Which of the following function is more appropriate for reading in a multi-word string?
A.
printf();
B.
scanf();
C.
gets();
D.
puts();
7. Which of the following function is correct that finds the length of a string?
A.
B.
int xstrlen(char s)
{
int length=0;
while(*s!='\0')
{ length++; s++; }
return (length);
C.
int length=0;
while(*s!='\0')
length++; s++;
return (length);
D.
CONST
1. What will be the output of the program?
#include<stdio.h>
int main()
{
int y=128;
const int x=y;
printf("%d\n", x);
return 0;
}
A.
128
B.
Garbage value
C.
Error
D.
B.
C.
D.
No error
Address of i
Address of j
B.
10
223
C.
Error: cannot convert parameter 1 from 'const int **' to 'int **'
D.
Garbage value
B.
10
C.
Error
D.
Garbage value
B.
C.
D.
Garbage value
Error
B.
C.
Hello
D.
Hel
Garbage value
B.
Error
C.
20
D.
{
const int arr[5] = {1, 2, 3, 4, 5};
printf("Before modification arr[3] = %d", arr[3]);
fun(&arr[3]);
printf("\nAfter modification arr[3] = %d", arr[3]);
return 0;
}
A.
B.
C.
D.
10
B.
11
C.
No output
D.
return 0;
}
A.
Error
B.
-11, 34
C.
11, 34
D.
None of these
COMPLICATED DECLARATIONS
1. Declare the following statement?
"An array of three pointers to chars".
A.
char *ptr[3]();
B.
char *ptr[3];
C.
char (*ptr[3])();
D.
char **ptr[3];
B.
C.
D.
char *ptr[3]();
B.
char (*ptr)*[3];
C.
char (*ptr[3])();
D.
char (*ptr)[3];
B.
C.
D.
pf is a pointer to function.
B.
pf is a function pointer.
C.
D.
6. Declare the following statement? "A pointer to a function which receives an int pointer and
returns float pointer".
A.
float *(ptr)*int;
B.
float *(*ptr)(int)
C.
float *(*ptr)(int*)
D.
float (*ptr)(int)
B.
C.
D.
void *(ptr)*int;
B.
void *(*ptr)()
C.
void *(*ptr)(*)
D.
void (*ptr)()
B.
C.
f is a function pointer.
D.
B.
C.
D.
B.
C.
D.
B.
C.
D.