C Programming

C Programming

Library Functions has 29 Questions
What will the function rewind() do?

Reposition the file pointer to a character reverse.
Reposition the file pointer stream to end of file.
Reposition the file pointer to begining of that line.
Reposition the file pointer to begining of file.
What will be the output of the program?
#include<stdio.h>

int main()
{
    int i;
    i = printf("How r u");
    i = printf("%d", i);
    printf("%d", i);
    return 0;
}

How r u
7
2
How r u
8
2
How r u
1
1
Error: cannot assign printf to variable
Point out the error in the following program.
#include<stdio.h>

int main()
{
    fprintf("ASTIWZ");
    printf("%.ef", 2.0);
    return 0;
}

Error: unknown value in printf() statement.
Error: in fprintf() statement.
No error and prints "ASTIWZ"
No error and prints "2.0"
It is necessary that for the string functions to work safely the strings must be terminated with ''.

True
False
Is standard library a part of C language?

Yes
No
Input/output function prototypes and macros are defined in which header file?

conio.h
stdlib.h
stdio.h
dos.h
What will be the output of the program?
#include<stdio.h>
#include<math.h>

int main()
{
    float i = 2.5;
    printf("%f, %d", floor(i), ceil(i));
    return 0;
}

2, 3
2.000000, 3
2.000000, 0
2, 0
Point out the error in the following program.
#include<stdio.h>
#include<string.h>

int main()
{
    char str1[] = "Learn through ASTIWZ.com",  str2[120];
    char *p;
    p = (char*) memccpy(str2, str1, 'i', strlen(str1));
    *p = '';
    printf("%s", str2);
    return 0;
}

Error: in memccpy statement
Error: invalid pointer conversion
Error: invalid variable declaration
No error and prints "Learn through Indi"
FILE is a structure suitably typedef'd in "stdio.h".

True
False
Will the program outputs "ASTIWZ.com"?
#include<stdio.h>
#include<string.h>

int main()
{
    char str1[] = "ASTIWZ.com";
    char str2[20];
    strncpy(str2, str1, 8);
    printf("%s", str2);
    return 0;
}

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

strnchar()
strchar()
strrchar()
strrchr()
What will be the output of the program?
#include<stdio.h>

int main()
{
    int i;
    i = scanf("%d %d", &i, &i);
    printf("%d", i);
    return 0;
}

1
2
Garbage value
Error: cannot assign scanf to variable
Point out the error in the following program.
#include<stdio.h>

int main()
{
    char str[] = "ASTIWZ";
    printf("%.#s %2s", str, str);
    return 0;
}

Error: in Array declaration
Error: printf statement
Error: unspecified character in printf
No error
ftell() returns the current position of the pointer in a file stream.

True
False
The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.

Yes
No
What is stderr ?

standard error
standard error types
standard error streams
standard error definitions
What will be the output of the program?
#include<stdio.h>

int main()
{
    int i;
    char c;
    for(i=1; i<=5; i++)
    {
        scanf("%c", &c); /* given input is 'b' */
        ungetc(c, stdout);
        printf("%c", c);
        ungetc(c, stdin);
    }
    return 0;
}

bbbb
bbbbb
b
Error in ungetc statement.
Data written into a file using fwrite() can be read back using fscanf()

True
False
The prototypes of all standard library string functions are declared in the file string.h.

Yes
No
Does there any function exist to convert the int or float to a string?

Yes
No
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    char *i = "55.555";
    int result1 = 10;
    float result2 = 11.111;
    result1 = result1+atoi(i);
    result2 = result2+atof(i);
    printf("%d, %f", result1, result2);
    return 0;
}

55, 55.555
66, 66.666600
65, 66.666000
55, 55
If the two strings are found to be unequal then strcmp returns difference between the first non-matching pair of characters.

True
False
scanf() or atoi() function can be used to convert a string like "436" in to integer.

Yes
No
What is the purpose of fflush() function.

flushes all streams and specified streams.
flushes only specified stream.
flushes input/output buffer.
flushes file buffer.
What will be the output of the program?
#include<stdio.h>
#include<string.h>

int main()
{
    char dest[] = {97, 97, 0};
    char src[] = "aaa";
    int i;
    if((i = memcmp(dest, src, 2))==0)
        printf("Got it");
    else
        printf("Missed");
    return 0;
}

Missed
Got it
Error in memcmp statement
None of above
Can you use the fprintf() to display the output on the screen?

Yes
No
What will function gcvt() do?

Convert vector to integer value
Convert floating-point number to a string
Convert 2D array in to 1D array.
Covert multi Dimensional array to 1D array
What will the function randomize() do in Turbo C under DOS?

returns a random number.
returns a random number generator in the specified range.
returns a random number generator with a random value based on time.
return a random number with a given seed value.
What will be the output of the program?
#include<stdio.h>

int main()
{
    int i;
    char c;
    for(i=1; i<=5; i++)
    {
        scanf("%c", &c); /* given input is 'a' */
        printf("%c", c);
        ungetc(c, stdin);
    }
    return 0;
}

aaaa
aaaaa
Garbage value.
Error in ungetc statement.