Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Input / Output Questions
C scanf formatting: Given float a; and double b;, which scanf statement uses the correct conversion specifiers to read both values from input?
Safe line input in C: Between fgets() and gets(), which function is considered safe for reading a line of text (and why)?
C printf formatting: With float a = 3.14; and double b = 3.14;, which printf statement uses correct specifiers to print both values?
Behavior of fgets with Windows newlines: If a file contains the line "I am a boy\r ", what exact byte sequence will the char array str contain after calling fgets(str, size, fp)?
C file I/O API correctness: In the given program with three opened files, what happens when calling fclose(fp, fs, ft);?
Meaning of mode string in fopen: In the call fp = fopen("source.txt", "rb"); what does the mode "rb" instruct the C library to do?
Understanding fileno: In the program that opens "DUMMY.C" for writing and assigns t = fileno(fp);, what does t represent?
What does the FILE* returned by fopen actually point to in C? Consider FILE fp; fp = fopen("trial", "r");
Effect of fseek in a read loop: Given the code that copies from source.txt to target.txt but calls fseek(fs, 4L, SEEK_CUR) after each character read, what will be written to 'target.txt' if the source line is "To err is human"?
C file modes: Given FILE *fp; fp = fopen('NOTES.TXT', 'r+'); which operations on the file are permitted by the mode 'r+' (read/update without truncation)?
In C file handling, two streams open the same file in write mode. After writing a character through each stream, what remains in the file? #include
int main() { FILE *fp1, *fp2; fp1 = fopen("file.c", "w"); fp2 = fopen("file.c", "w"); fputc('A', fp1); fputc('B', fp2); fclose(fp1); fclose(fp2); return 0; }
In C formatting, what is the exact output produced by adjacent string literal concatenation and a ternary expression? #include
int main() { int k = 1; printf("%d == 1 is" "%s ", k, k == 1 ? "TRUE" : "FALSE"); return 0; }
In C file I/O, what happens when fgetc() is compared to NULL and the character variable is of type char? #include
int main() { FILE *ptr; char i; ptr = fopen("myfile.c", "r"); while ((i = fgetc(ptr)) != NULL) printf("%c", i); return 0; }
In C printf formatting, what is the rounded output for a floating value with one digit after the decimal point? #include
int main() { float a = 3.15529f; printf("%2.1f ", a); return 0; }
In C printf, assume the intent is to print a decimal integer with a minimal field width of 1. What does this program output (ignoring a stray non-printing control glyph in the source)? #include
int main() { int a = 250; printf("%1d", a); /* treat the strange trailing glyph as a typo and consider %1d */ return 0; }
In C file positioning, given a file containing "This is Nagpur", what substring is printed after seeking forward and reading with fgets? #include
int main() { FILE fp; char ch, str[7]; fp = fopen("try.c", "r"); / file 'try.c' contains: This is Nagpur / fseek(fp, 9L, SEEK_CUR); / move 9 bytes from the current position (start) / fgets(str, 5, fp); / read up to 4 chars plus '\0' */ puts(str); return 0; }
In C, what does scanf return when it successfully reads one decimal integer? Consider the following minimal program and assume the user enters 25. #include
int main() { int i; printf("%d ", scanf("%d", &i)); return 0; }
In C file I/O, what does this program print from a file until EOF, and what happens in the final printf call? #include
#include
int main() { FILE fp; unsigned char ch; / file 'abc.c' contains: "This is CuriousTab " / 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(" ", ch); / prints just a newline; extra argument is ignored */ return 0; }
In C programming, evaluate the character printed by this expression that mixes arithmetic and bitwise operators. What will be the output? #include
int main() { printf("%c ", ~('C' * -1)); return 0; }
In C, pointer arithmetic on a format string: what does this print? #include
int main() { char *p; p = "%d "; p++; p++; printf(p - 2, 23); return 0; }
1
2