C Programming > Library Functions

C Programming Questions and Answers

C Programming > Library Functions

Postby abdulsaboor » Thu Oct 02, 2014 11:39 am

C Programming > Library Functions

1.
What will the function rewind() do?

A. Reposition the file pointer to a character reverse.
B. Reposition the file pointer stream to end of file.
C. Reposition the file pointer to begining of that line.
D. Reposition the file pointer to begining of file.

Answer: Option D

Explanation:

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);
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Thu Oct 02, 2014 11:41 am

2.
Input/output function prototypes and macros are defined in which header file?

A. conio.h
B. stdlib.h
C. stdio.h
D. dos.h

Answer: Option C

Explanation:

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.
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Thu Oct 02, 2014 11:43 am

3.
Which standard library function will you use to find the last occurance of a character in a string in C?

A. strnchar()
B. strchar()
C. strrchar()
D. strrchr()

Answer: Option D

Explanation:

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.
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Thu Oct 02, 2014 11:44 am

4.
What is stderr ?

A. standard error
B. standard error types
C. standard error streams
D. standard error definitions

Answer: Option C

Explanation:

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).
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Thu Oct 02, 2014 11:46 am

5.
Does there any function exist to convert the int or float to a string?

A. Yes
B. No

Answer: Option A

Explanation:

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
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Sat Oct 04, 2014 9:52 am

6.
What is the purpose of fflush() function.

A. flushes all streams and specified streams.
B. flushes only specified stream.
C. flushes input/output buffer.
D. flushes file buffer.

Answer: Option A

Explanation:

"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.
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Sat Oct 04, 2014 9:53 am

7.
Can you use the fprintf() to display the output on the screen?

A. Yes
B. No

Answer: Option A

Explanation:

Do like this fprintf(stdout, "%s %d %f", str, i, a);
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan

Re: C Programming > Library Functions

Postby abdulsaboor » Sat Oct 04, 2014 9:54 am

8.
What will the function randomize() do in Turbo C under DOS?

A. returns a random number.
B. returns a random number generator in the specified range.
C. returns a random number generator with a random value based on time.
D. return a random number with a given seed value.

Answer: Option C

Explanation:

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;
}
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
 
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan


Return to C Programming

Who is online

Users browsing this forum: No registered users and 1 guest
cron