C Programming - Input / Output

6.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("%c\n", ~('C'*-1));
    return 0;
}
A
B
C
D
Answer: Option
Explanation:
No answer description is available. Let's discuss.

7.
What will be the output of the program ?
#include<stdio.h>

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;
}
This is IndiaBIX
This is
Infinite loop
Error
Answer: Option
Explanation:

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.


8.
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;
}
21
23
Error
No output
Answer: Option
Explanation:
No answer description is available. Let's discuss.

9.
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;
}
Print the contents of file "myfile.c"
Print the contents of file "myfile.c" upto NULL character
Infinite loop
Error in program
Answer: Option
Explanation:
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.

10.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    printf("%%%%\n");
    return 0;
}
%%%%%
%%
No output
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.