Sie sind auf Seite 1von 6

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?

a = f1(23, 14) * f2(12/4) + f3();


A. B. C. D. 4. f1, f2, f3 f3, f2, f1 Order may vary from compiler to compiler None of above In which order do the following gets evaluated

1. Relational 2. Arithmetic 3. Logical 4. Assignment A. C. 2134 4321 B. D. 1234 3214

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.

"I am a boy\r\n\0" "I am a boy\n\0"

B. D.

"I am a boy\r\0" "I am a boy"

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);

} } return 0; } A. C. rn err B. D. Trh None of above

9. 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; } A. B. C. D. Error: in unsigned char statement Error: unknown file pointer No error None of above

10. Point out the error in the program?


#include<stdio.h>
/* Assume there is a file called 'file.c' in c:\tc directory. */ int main() { FILE *fp; fp=fopen("c:\tc\file.c", "r"); if(!fp) printf("Unable to open file."); fclose(fp); return 0; }

A. B. C. D.

No error, No output. Program crashes at run time. Output: Unable to open file. None of above

11. Point out the error/warning in the program?

#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"

12. Which of the following statement is correct about the program?

#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?

#include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4


int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0; } A. C. memfree(int p); malloc(p, 0); B. D. dealloc(p); free(p);

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++; }

return 0; } A. C. Infinite times 256 times B. D. 255 times 254 times

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

Das könnte Ihnen auch gefallen