of 31
1.In a file contains the line "I am a boy\r\n" then on reading this line into the arraystrusingfgets(). What willstrcontain?
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"
Answer:OptionCExplanation:Declaration:char *fgets(char *s, int n, FILE *stream);fgetsreads characters from stream into the strings. It stops when it reads either n - 1 characters or a newline character, whichever comes first.Therefore, the stringstrcontain "I am a boy\n\0"2.Point out the error in the program?#include#include
int main(){unsignedchar; FILE *fp;fp=fopen("trial", "r");if(!fp) {printf("Unable to open file"); exit(1); }fclose(fp);return0;}
A.A. Error: inunsigned charstatement
B.B. Error: unknown file pointer
C.C. No error
D.D. None of above
Answer:OptionCExplanation:This program tries to open the filetrial.txtin read mode. If file not exists or unable to read it prints"Unable to open file"and then terminate the program.If file exists, it simply close the file and then terminates the program.3. Point out the error in the following program.#include#include
int main(){char *ptr; *ptr = (char)malloc(30);strcpy(ptr, "RAM");printf("%s", ptr); free(ptr);return0;}
A.Error: instrcpy()statement.
B.Error: in*ptr = (char)malloc(30);
C.Error: infree(ptr);
D.No error
Answer:OptionBExplanation:Answer:ptr = (char*)malloc(30);4. What will be the output of the program?#includeint main(){inti=0;for(; i