Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

The library function used to reverse a string is

Answer» strrev(s) Reverses all characters in s Example: #include <string.h> #include <stdio.h> int main(void) { char *str = "IndiaBIX"; printf("Before strrev(): %s\n", str); strrev(str); printf("After strrev(): %s\n", str); return 0; } Output: Before strrev(): IndiaBIX After strrev(): XIBaidnI
2.

What will be the output of the program in Turbo C?

Answer» str[6] = "BIX"; - Nonportable pointer conversion.
3.

If and bytes size, What will be the output of the program ?

Answer» Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with value 'A'. Step 2: printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14)); The sizeof function returns the size of the given expression. sizeof(ch) becomes sizeof(char). The size of char is 1 byte. sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question). sizeof(3.14f). The size of float is 4 bytes. Hence the output of the program is 1, 4, 4
4.

What will be the output of the program (Turbo C in 16 bit platform DOS) ?

Answer» It prints 'IndiaBIX IndiaBIX' in TurboC (in 16 bit platform). It may cause a 'segmentation fault error' in GCC (32 bit platform).
5.

If the size of pointer is 4 bytes then What will be the output of the program ?

Answer» Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The variable str is declared as an pointer to the array of 6 strings. Step 2: printf("%d, %d", sizeof(str), strlen(str[0])); sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24' strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5'; Hence the output of the program is 24, 5 Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes).
6.

What will be the output of the program in 16-bit platform (Turbo C under DOS) ?

Answer» Step 1: printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0)); The sizeof function returns the size of the given expression. sizeof(3.0f) is a floating point constant. The size of float is 4 bytes sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes sizeof(3.0) is a double constant. The size of double is 8 bytes Hence the output of the program is 4,2,8 Note: The above program may produce different output in other platform due to the platform dependency of C compiler. In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.
7.

What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?

Answer» Step 1: void fun(); This is the prototype for the function fun(). Step 2: fun(); The function fun() is called here. The function fun() gets a character input and the input is terminated by an enter key(New line character). It prints the given character in the reverse order. The given input characters are "abc" Output: cba
8.

Is there any difference between the two statements?

Answer» In first statement the character pointer ch stores the address of the string "IndiaBIX".The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
9.

If the two strings are identical, then function returns

Answer» Declaration: strcmp(const char *s1, const char*s2); The strcmp return an int value that is if s1 < s2 returns a value < 0 if s1 == s2 returns 0 if s1 > s2 returns a value > 0
10.

How will you print \n on the screen?

Answer» The statement printf("\\n"); prints '\n' on the screen.
11.

The library function used to find the last occurrence of a character in a string is

Answer» Declaration: char *strrchr(const char *s, int c); It scans a string s in the reverse direction, looking for a specific character c. Example: #include <string.h> #include <stdio.h> int main(void) { char text[] = "I learn through IndiaBIX.com"; char *ptr, c = 'i'; ptr = strrchr(text, c); if (ptr) printf("The position of '%c' is: %d\n", c, ptr-text); else printf("The character was not found\n"); return 0; } Output: The position of 'i' is: 19