Vidyalelo
C Programming · all questions

File Input Output
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

296

Questions

11/15

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    FILE *fp = stdin;
    int n;
    fprintf(fp, "%d", 45);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
    char *str = "hello, world";
    char *str1 = "hello, world";
    if (strcmp(str, str1))
        printf("equal");
    else
        printf("unequal");
}

Select an option to see the answer and solution.

What is the function of FILE *tmpfile(void)?

Select an option to see the answer and solution.

What happens when zero flag is used with left justification?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int n;
    scanf("%d", n);
    printf("%d\n", n);
    return 0;
}

Select an option to see the answer and solution.

Which of the following is not a valid mathematical function?

Select an option to see the answer and solution.

EOF is an integer type defined in stdio. hand has a value . . . . . . . .

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
    char *str = "hello, world";
    char str1[9];
    strncpy(str1, str, 9);
    printf("%s %d", str1, strlen(str1));
}

Select an option to see the answer and solution.

What will be the output of the following C code if following commands are used to run and if myfile does not exist?
gcc -o test test.c
./test > myfile

#include <stdio.h>
int main(int argc, char **argv)
{
    char c = 'd';
    putchar(c);
    printf(" %d\n", argc);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    char c = '�';
    putchar(c);
}

Select an option to see the answer and solution.

What is function srand(unsigned)?

Select an option to see the answer and solution.

What is the purpose of the C function?
int ferror(FILE *fp)

Select an option to see the answer and solution.

What if size is zero in the following C statement?
realloc(ptr, size)

Select an option to see the answer and solution.

Select the right explanation to the given code.
printf(“%*. *f”, 5,4,5700);

Select an option to see the answer and solution.

Which of the following should be used for freeing the memory allocated in the following C code?
#include <stdio.h>
struct p
{
    struct p *next;
    int x;
};
int main()
{
    struct p *p1 = (struct p*)malloc(sizeof(struct p));
    p1->x = 1;
    p1->next = (struct p*)malloc(sizeof(struct p));
    return 0;
}

Select an option to see the answer and solution.

Which of the following function with ellipsis are illegal?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    struct p *next;
    int x;
};
int main()
{
    struct p *p1 = calloc(1, sizeof(struct p));
    p1->x = 1;
    p1->next = calloc(1, sizeof(struct p));
    printf("%d\n", p1->next->x);
    return 0;
}

Select an option to see the answer and solution.

Which of the following mathematical function requires 2 parameter for successful function call?

Select an option to see the answer and solution.

How many characters for pushback is guaranteed per file while using ungetc(c, fp);?

Select an option to see the answer and solution.

Which of the following function can be used to terminate the main() function from another function safely?

Select an option to see the answer and solution.