

InterviewSolution
Saved Bookmarks
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. |
What is the purpose of function. |
Answer» "fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess. Example: fflush(FilePointer); fflush(NULL); flushes all streams. | |
2. |
Can you use the to display the output on the screen? |
Answer» Do like this fprintf(stdout, "%s %d %f", str, i, a); | |
3. |
What will the function do in Turbo C under DOS? |
Answer» The randomize() function initializes the random number generator with a random value based on time. You can try the sample program given below in Turbo-C, it may not work as expected in other compilers. /* Prints a random number in the range 0 to 99 */ #include <stdlib.h> #include <stdio.h> #include <time.h> int main(void) { randomize(); printf("Random number in the 0-99 range: %d\n", random (100)); return 0; } | |
4. |
It is necessary that for the string functions to work safely the strings must be terminated with '\0'. |
Answer» C string is a character sequence stored as a one-dimensional character array and terminated with a null character('\0', called NULL in ASCII). The length of a C string is found by searching for the (first) NULL byte. | |
5. |
is a structure suitably 'd in "stdio.h". |
Answer» FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including: => a file descriptor, the current stream position, => an end-of-file indicator, => an error indicator, => a pointer to the stream's buffer, if applicable fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file. size_t - an unsigned integer type which is the type of the result of the sizeof operator. | |
6. |
returns the current position of the pointer in a file stream. |
Answer» The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream. Example: #include <stdio.h>int main(void){ FILE *stream; stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("The file pointer is at byte %ld\n", ftell(stream)); fclose(stream); return 0;} | |
7. |
Data written into a file using can be read back using |
Answer» fwrite() - Unformatted write in to a file. fscanf() - Formatted read from a file. | |
8. |
If the two strings are found to be unequal then returns difference between the first non-matching pair of characters. |
Answer» g = strcmp(s1, s2); returns 0 when the strings are equal, a negative integer when s1 is less than s2, or a positive integer if s1 is greater than s2, that strcmp() not only returns -1, 0 and +1, but also other negative or positive values(returns difference between the first non-matching pair of characters between s1 and s2). A possible implementation for strcmp() in "The Standard C Library". int strcmp (const char * s1, const char * s2){ for(; *s1 == *s2; ++s1, ++s2) { if(*s1 == 0) return 0; } return *(unsigned char *)s1 < *(unsigned char *)s2 ? -1 : 1;} | |
9. |
What will function do? |
Answer» The gcvt() function converts a floating-point number to a string. It converts given value to a null-terminated string. #include <stdlib.h>#include <stdio.h>int main(void){ char str[25]; double num; int sig = 5; /* significant digits */ /* a regular number */ num = 9.876; gcvt(num, sig, str); printf("string = %s\n", str); /* a negative number */ num = -123.4567; gcvt(num, sig, str); printf("string = %s\n", str); /* scientific notation */ num = 0.678e5; gcvt(num, sig, str); printf("string = %s\n", str); return(0);} Output: string = 9.876string = -123.46string = 67800 | |
10. |
Is standard library a part of C language? |
Answer» The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and string handling, in the C programming language. The C standard library is an interface standard described by a document; it is not an actual library of software routines available for linkage to C programs. | |
11. |
Will the program outputs "IndiaBIX.com"? |
Answer» No. It will print something like 'IndiaBIX(some garbage values here)' . Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with IndiaBIX. | |
12. |
The function can convert an integer in decimal, octal or hexadecimal form to a string. |
Answer» itoa() takes the integer input value input and converts it to a number in base radix. The resulting number a sequence of base-radix digits. Example: /* itoa() example */#include <stdio.h>#include <stdlib.h>int main (){ int no; char buff [50]; printf ("Enter number: "); scanf ("%d",&no); itoa (no,buff,10); printf ("Decimal: %s\n",buff); itoa (no,buff,2); printf ("Binary: %s\n",buff); itoa (no,buff,16); printf ("Hexadecimal: %s\n",buff); return 0;} Output:Enter a number: 1250Decimal: 1250Binary: 10011100010Hexadecimal: 4e2 | |
13. |
The prototypes of all standard library string functions are declared in the file . |
Answer» string.h is the header in the C standard library for the C programming language which contains macro definitions, constants, and declarations of functions and types used not only for string handling but also various memory handling functions. | |
14. |
or function can be used to convert a string like "436" in to integer. |
Answer» scanf is a function that reads data with specified format from a given string stream source. scanf("%d",&number); atoi() convert string to integer. var number; number = atoi("string"); | |
15. |
What will the function do? |
Answer» rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file. Example: rewind(FilePointer); | |
16. |
Input/output function prototypes and macros are defined in which header file? |
Answer» stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations. | |
17. |
Which standard library function will you use to find the last occurance of a character in a string in C? |
Answer» strrchr() returns a pointer to the last occurrence of character in a string. Example: #include <stdio.h>#include <string.h>int main(){ char str[30] = "12345678910111213"; printf("The last position of '2' is %d.\n", strrchr(str, '2') - str); return 0;} Output: The last position of '2' is 14. | |
18. |
What is ? |
Answer» The standard error(stderr) stream is the default destination for error messages and other diagnostic warnings. Like stdout, it is usually also directed to the output device of the standard console (generally, the screen). | |
19. |
Does there any function exist to convert the or to a ? |
Answer» 1. itoa() converts an integer to a string. 2. ltoa() converts a long to a string. 3. ultoa() converts an unsigned long to a string. 4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to string type. #include<stdio.h> #include<stdlib.h> int main(void) { int num1 = 12345; float num2 = 5.12; char str1[20]; char str2[20]; itoa(num1, str1, 10); /* 10 radix value */ printf("integer = %d string = %s \n", num1, str1); sprintf(str2, "%f", num2); printf("float = %f string = %s", num2, str2); return 0; } // Output: // integer = 12345 string = 12345 // float = 5.120000 string = 5.120000 | |