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. rem = 3.14 % 2.1; rem = modf(3.14, 2.1); rem = fmod(3.14, 2.1); Remainder cannot be obtain in floating point division.
2.
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
A. C. 3. */%+-= /*%-+= B. D. =*/%+*%/-+=
Which of the following is the correct order if calling functions in the below code?
5. 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. C.
B. D.
6. 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. C. Reading Appending B. D. Writing Read and Write
7. 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. C. "A.C" "B.C" "C.C" "A.C" B. D. "B.C" "C.C" Error in fclose()
8.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);
#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; } A. B. C. D. Error: in unsigned char statement Error: unknown file pointer No error None of above
A. B. C. D.
No error, No output. Program crashes at run time. Output: Unable to open file. None of above
#include<stdio.h>
int main() { unsigned char ch; FILE *fp; fp=fopen("trial", "r"); while((ch = getc(fp))!=EOF) printf("%c", ch); fclose(fp); return 0; } A. B. C. D. Error: in unsigned char declaration Error: while statement No error It prints all characters in file "trial"
#include<stdio.h>
int main() { FILE *fp; char str[11], ch; int i=0; fp = fopen("INPUT.TXT", "r"); while((ch=getc(fp))!=EOF) { if(ch == '\n' || ch == ' ') { str[i]='\0'; strrev(str); printf("%s", str); i=0; } else str[i++]=ch;
} fclose(fp); return 0; } A. B. C. D. The code writes a text to a file The code reads a text files and display its content in reverse order The code writes a text to a file in reverse order None of above
13.We should not read after a write to a file without an intervening call to fflush(), fseek() or
rewind()
A. True B. False
14. A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character. A. True B. False
15. How will you free the memory allocated by the following program?
16.How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; }
17. Which of the following cannot be checked in a switch-case statement? A. C. Character Float B. D. Integer enum
18. How many bytes are occupied by near, far and huge pointers (DOS)? A. C. near=2 far=4 huge=4 near=2 far=4 huge=8 B. D. near=4 far=8 huge=8 near=4 far=4 huge=8
19. What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
A. C. ((((a+i)+j)+k)+l) (((a+i)+j)+k+l) B. D. *(*(*(*(a+i)+j)+k)+l) ((a+i)+j+k+l)
20. A pointer is A. B. C. D. A keyword used to create variables A variable that stores address of an instruction A variable that stores address of other variable All of the above