Exercise: Input Output
Questions for: Input Output
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf("%%%%\n");
return 0;
}
A:
%%%%%
B:
%%
C:
No output
D:
Error
Answer: B
No answer description is available. Let's discuss.
What will be the output of the program ?
#include<stdio.h>
int main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
A:
Print the contents of file "myfile.c"
B:
Print the contents of file "myfile.c" upto NULL character
C:
Infinite loop
D:
Error in program
Answer: C
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.
Discuss About this Question.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2, 23);
return 0;
}
A:
21
B:
23
C:
Error
D:
No output
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
What will be the output of the program ?
#include<stdio.h>
int main()
{
FILE *fp;
unsigned char ch;
/* file 'abc.c' contains "This is ExamAdept " */
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;
}
A:
This is ExamAdept
B:
This is
C:
Infinite loop
D:
Error
Answer: C
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.
Discuss About this Question.
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf("%c\n", ~('C'*-1));
return 0;
}
A:
A
B:
B
C:
C
D:
D
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.