C Programming Input / Output Online Test, C Programming Mock Quiz
C Programming Input / Output Online Test
Finish Quiz
0 of 30 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
Information
C Programming Input / Output Online Test. C Programming Question and Answers in English. C Programming Input / Output Online mock test paper is free for all students and Very Helpful for Exam Preparation. C Programming Input / Output Online Quiz. C Programming Online Mock test for Input / Output Topic. Here we are providing C Programming Input / Output Online Test Series in English. Check C Programming Mock Test Series 2019-2019.
This paper has 30 questions.
Time allowed is 30 minutes.
The C Programming online Mock Test Exam is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 30 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- Answered
- Review
-
Question 1 of 30
1. Question
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?
Correct
Declaration: char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the string s. It stops when it reads either n – 1 characters or a newline character, whichever comes first.
Therefore, the string str contain “I am a boy\n\0”
Incorrect
Declaration: char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the string s. It stops when it reads either n – 1 characters or a newline character, whichever comes first.
Therefore, the string str contain “I am a boy\n\0”
-
Question 2 of 30
2. Question
What is the purpose of “rb” in fopen() function used below in the code?
FILE *fp; fp = fopen("source.txt", "rb");
Correct
The file source.txt will be opened in the binary mode.
Incorrect
The file source.txt will be opened in the binary mode.
-
Question 3 of 30
3. Question
What does fp point to in the program ?
#include
int main() { FILE *fp; fp=fopen("trial", "r"); return 0; } Correct
The fp is a structure which contains a char pointer which points to the first character of a file.
Incorrect
The fp is a structure which contains a char pointer which points to the first character of a file.
-
Question 4 of 30
4. Question
Which of the following operations can be performed on the file “NOTES.TXT” using the below code?
FILE *fp; fp = fopen("NOTES.TXT", "r+");
Correct
r+ Open an existing file for update (reading and writing).
Incorrect
r+ Open an existing file for update (reading and writing).
-
Question 5 of 30
5. Question
To print out a and b given below, which of the following printf() statement will you use?
#include
float a=3.14; double b=3.14; Correct
To print a float value, %f is used as format specifier.
To print a double value, %lf is used as format specifier.
Therefore, the answer is printf(“%f %lf”, a, b);
Incorrect
To print a float value, %f is used as format specifier.
To print a double value, %lf is used as format specifier.
Therefore, the answer is printf(“%f %lf”, a, b);
-
Question 6 of 30
6. Question
Which files will get closed through the fclose() in the following program?
#include
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; } Correct
Extra parameter in call to fclose().
Incorrect
Extra parameter in call to fclose().
-
Question 7 of 30
7. Question
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
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; } Correct
The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains “To err is human”.
Inside the while loop,
ch=getc(fs); The first character(‘T’) of the source.txt is stored in variable ch and it’s checked for EOF.
if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.
If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.
fputc(ch, ft); It writes the character ‘T’ stored in variable ch to target.txt.
The while loop runs three times and it write the character 1st and 5th and 11th characters (“Trh”) in the target.txt file.
Incorrect
The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains “To err is human”.
Inside the while loop,
ch=getc(fs); The first character(‘T’) of the source.txt is stored in variable ch and it’s checked for EOF.
if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.
If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.
fputc(ch, ft); It writes the character ‘T’ stored in variable ch to target.txt.
The while loop runs three times and it write the character 1st and 5th and 11th characters (“Trh”) in the target.txt file.
-
Question 8 of 30
8. Question
To scan a and b given below, which of the following scanf() statement will you use?
#include
float a; double b; Correct
To scan a float value, %f is used as format specifier.
To scan a double value, %lf is used as format specifier.
Therefore, the answer is scanf(“%f %lf”, &a, &b);
Incorrect
To scan a float value, %f is used as format specifier.
To scan a double value, %lf is used as format specifier.
Therefore, the answer is scanf(“%f %lf”, &a, &b);
-
Question 9 of 30
9. Question
Out of fgets() and gets() which function is safe to use?
Correct
Because, In fgets() we can specify the size of the buffer into which the string supplied will be stored.
Incorrect
Because, In fgets() we can specify the size of the buffer into which the string supplied will be stored.
-
Question 10 of 30
10. Question
Consider the following program and what will be content of t?
#include
int main() { FILE *fp; int t; fp = fopen("DUMMY.C", "w"); t = fileno(fp); printf("%d\n", t); return 0; } Correct
fp = fopen(“DUMMY.C”, “w”); A file DUMMY.C is opened in write mode and returns the file pointer to fp
t = fileno(fp); returns the handle for the fp stream and it stored in the variable t
printf(“%d\n”, t); It prints the handle number.
Incorrect
fp = fopen(“DUMMY.C”, “w”); A file DUMMY.C is opened in write mode and returns the file pointer to fp
t = fileno(fp); returns the handle for the fp stream and it stored in the variable t
printf(“%d\n”, t); It prints the handle number.
-
Question 11 of 30
11. Question
What will be the content of ‘file.c’ after executing the following program?
#include
Correct
Here fputc(‘A’, fp1); stores ‘A’ in the file1.c then fputc(‘B’, fp2); overwrites the contents of the file1.c with value ‘B’. Because the fp1 and fp2 opens the file1.c in write mode.
Hence the file1.c contents is ‘B’.
Incorrect
Here fputc(‘A’, fp1); stores ‘A’ in the file1.c then fputc(‘B’, fp2); overwrites the contents of the file1.c with value ‘B’. Because the fp1 and fp2 opens the file1.c in write mode.
Hence the file1.c contents is ‘B’.
-
Question 12 of 30
12. Question
What will be the output of the program ?
#include
int main() { int k=1; printf("%d == 1 is" "%s\n", k, k==1?"TRUE":"FALSE"); return 0; } Correct
Step 1: int k=1; The variable k is declared as an integer type and initialized to ‘1’.
Step 2: printf(“%d == 1 is” “%s\n”, k, k==1?”TRUE”:”FALSE”); becomes
=> k==1?”TRUE”:”FALSE”
=> 1==1?”TRUE”:”FALSE”
=> “TRUE”
Therefore the output of the program is 1 == 1 is TRUE
Incorrect
Step 1: int k=1; The variable k is declared as an integer type and initialized to ‘1’.
Step 2: printf(“%d == 1 is” “%s\n”, k, k==1?”TRUE”:”FALSE”); becomes
=> k==1?”TRUE”:”FALSE”
=> 1==1?”TRUE”:”FALSE”
=> “TRUE”
Therefore the output of the program is 1 == 1 is TRUE
-
Question 13 of 30
13. Question
What will be the output of the program ?
#include
char *str = "char *str = %c%s%c; main(){ printf(str, 34, str, 34);}"; int main() { printf(str, 34, str, 34); return 0; } Correct
Incorrect
-
Question 14 of 30
14. Question
If the file ‘source.txt’ contains a line “Be my friend” which of the following will be the output of below program?
#include
Correct
The file source.txt contains “Be my friend”.
fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file.
fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters.
fgets(c, 5, fs); read the file from the current position of the file pointer.
Hence, it contains the last 3 characters of “Be my friend”.
Therefore, it prints “end”.
Incorrect
The file source.txt contains “Be my friend”.
fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file.
fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters.
fgets(c, 5, fs); read the file from the current position of the file pointer.
Hence, it contains the last 3 characters of “Be my friend”.
Therefore, it prints “end”.
-
Question 15 of 30
15. Question
What will be the output of the program ?
#include
int main() { float a=3.15529; printf("%2.1f\n", a); return 0; } Correct
float a=3.15529; The variable a is declared as an float data type and initialized to value 3.15529;
printf(“%2.1f\n”, a); The precision specifier tells .1f tells the printf function to place only one number after the .(dot).
Hence the output is 3.2
Incorrect
float a=3.15529; The variable a is declared as an float data type and initialized to value 3.15529;
printf(“%2.1f\n”, a); The precision specifier tells .1f tells the printf function to place only one number after the .(dot).
Hence the output is 3.2
-
Question 16 of 30
16. Question
What will be the output of the program ?
#include
int main() { printf("%c\n", ~('C'*-1)); return 0; } Correct
Incorrect
-
Question 17 of 30
17. Question
What will be the output of the program ?
#include
int main() { FILE *fp; unsigned char ch; /* file 'abc.c' contains "This is IndiaBIX " */ fp=fopen("abc.c", "r"); if(fp == NULL) { printf("Unable to open file"); exit(1); } while((ch=getc(fp)) != EOF) printf("%c", ch); fclose(fp); printf("\n", ch); return 0; } Correct
The macro EOF means -1.
while((ch=getc(fp)) != EOF) Here getc function read the character and convert it to an integer value and store it in the variable ch, but it is declared as an unsigned char. So the while loop runs infinitely.
Incorrect
The macro EOF means -1.
while((ch=getc(fp)) != EOF) Here getc function read the character and convert it to an integer value and store it in the variable ch, but it is declared as an unsigned char. So the while loop runs infinitely.
-
Question 18 of 30
18. Question
What will be the output of the program ?
#include
int main() { char *p; p="%d\n"; p++; p++; printf(p-2, 23); return 0; } Correct
Incorrect
-
Question 19 of 30
19. Question
What will be the output of the program ?
#include
int main() { FILE *ptr; char i; ptr = fopen("myfile.c", "r"); while((i=fgetc(ptr))!=NULL) printf("%c", i); return 0; } Correct
The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop.Incorrect
The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop. -
Question 20 of 30
20. Question
What will be the output of the program ?
#include
int main() { printf("%%%%\n"); return 0; } Correct
Incorrect
-
Question 21 of 30
21. Question
What will be the output of the program ?
#include
int main() { int a=250; printf("%1d\n", a); return 0; } Correct
int a=250; The variable a is declared as an integer type and initialized to value 250.
printf(“%1d\n”, a); It prints the value of variable a.
Hence the output of the program is 250.
Incorrect
int a=250; The variable a is declared as an integer type and initialized to value 250.
printf(“%1d\n”, a); It prints the value of variable a.
Hence the output of the program is 250.
-
Question 22 of 30
22. Question
What will be the output of the program ?
#include
Correct
Incorrect
-
Question 23 of 30
23. Question
What will be the output of the program if value 25 given to scanf()?
#include
int main() { int i; printf("%d\n", scanf("%d", &i)); return 0; } Correct
The scanf function returns the number of input is given.
printf(“%d\n”, scanf(“%d”, &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is ‘1’.
Incorrect
The scanf function returns the number of input is given.
printf(“%d\n”, scanf(“%d”, &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is ‘1’.
-
Question 24 of 30
24. Question
Point out the error in the program?
#include
#include int main() { unsigned char; FILE *fp; fp=fopen("trial", "r"); if(!fp) { printf("Unable to open file"); exit(1); } fclose(fp); return 0; } Correct
This program tries to open the file trial.txt in 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.
Incorrect
This program tries to open the file trial.txt in 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.
-
Question 25 of 30
25. Question
Point out the error in the program?
#include
int main() { char ch; int i; scanf("%c", &i); scanf("%d", &ch); printf("%c %d", ch, i); return 0; } Correct
Incorrect
-
Question 26 of 30
26. Question
Point out the error in the program?
#include
int main() { FILE *fp; fp=fopen("trial", "r"); fseek(fp, "20", SEEK_SET); fclose(fp); return 0; } Correct
Instead of “20” use 20L since fseek() need a long offset value.Incorrect
Instead of “20” use 20L since fseek() need a long offset value. -
Question 27 of 30
27. Question
Point out the error in the program?
#include
/* 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; } Correct
The path of file name must be given as “c:\\tc\file.c”Incorrect
The path of file name must be given as “c:\\tc\file.c” -
Question 28 of 30
28. Question
Point out the error/warning in the program?
#include
Correct
Here, EOF is -1. As ‘ch’ is declared as unsigned char it cannot deal with any negative value.Incorrect
Here, EOF is -1. As ‘ch’ is declared as unsigned char it cannot deal with any negative value. -
Question 29 of 30
29. Question
Which of the following statement is correct about the program?
#include
int main() { FILE *fp; char ch; int i=1; fp = fopen("myfile.c", "r"); while((ch=getc(fp))!=EOF) { if(ch == '\n') i++; } fclose(fp); return 0; } Correct
This program counts the number of lines in the file myfile.c by counting the character ‘\n’ in that file.
Incorrect
This program counts the number of lines in the file myfile.c by counting the character ‘\n’ in that file.
-
Question 30 of 30
30. Question
Which of the following statement is correct about the program?
#include
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; } Correct
This program reads the file INPUT.TXT and store it in the string str after reversing the string using strrev function.
Incorrect
This program reads the file INPUT.TXT and store it in the string str after reversing the string using strrev function.