AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 1 - 10 of 10 questions

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.

correct answer d
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);

2

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.

correct answer d
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);

3

What will be the output of the program?

#include < stdio . h >#includeint main()
{
    float i = 2.5;
    printf("%f, %d", floor(i), ceil(i));
    return0;
}
a

2, 3

b

2.000000, 3

c

2.000000, 0

d

2, 0

correct answer c

Answer :

Option C

Explanation :

Both ceil() and floor() return the integer found as a double.
floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is 2.000000.
ceil(2.5) returns 3, while converting the double to int it returns '0'.
So, the output is '2.000000,

4

What will be the output of the program?

#include < stdio . h >int main()
{
    int i;
    i = scanf("%d %d", &i, &i);
    printf("%d\n", i);
    return0;
}
a

1

b

2

c

Garbage value

d

Error: cannot assign scanf to variable

correct answer b
Answer :

Option B

Explanation :

scanf() returns the number of variables to which you are provding the input.
i = scanf("%d %d", &i, &i); Here Scanf() returns 2. So i = 2.
printf("%d\n", i); Here it prints 2.

5

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);
    }
    return0;
}
a

bbbb

b

bbbbb

c

b

d

Error in ungetc statement.

correct answer c
Answer :

Option C

Explanation :

The ungetc() function pushes the character c back onto the named input stream, which must be open for reading.
This character will be returned on the next call to getc or fread for that stream.
One character can be pushed back in all situations.
A second call to ungetc without a call to getc will force the previous character to be forgotten.

6

What will be the output of the program?

#include < stdio . h >#includeint 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);
    return0;
}

 


a

55, 55.555

b

66, 66.666600

c

65, 66.666000

d

55,55

correct answer c
Answer :

Option C

Explanation :

Function atoi() converts the string to integer.
Function atof() converts the string to float.

result1 = result1+atoi(i);
Here result1 = 10 + atoi(55.555);
result1 = 10 + 55;
result1 = 65;

result2 = result2+atof(i);
Here result2 = 11.111 + atof(55.555);
result2 = 11.111 + 55.555000;
result2 = 66.666000;
So the output is "65, 66.666000" .

7

What will be the output of the program?

#include < stdio . h >#includeint main()
{
    char dest[] = {97, 97, 0};
    char src[] = "aaa";
    int i;
    if((i = memcmp(dest, src, 2))==0)
        printf("Got it");
    elseprintf("Missed");
    return0;
}
a

Missed

b

Got it

c

Error in memcmp statement

d

None of above

correct answer b
Answer :

Option B

Explanation :

memcmp compares the first 2 bytes of the blocks dest and src as unsigned chars. So, the ASCII value of 97 is 'a'.
if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the first 2 bytes are same in both variables.so memcmp returns '0'.
Then, the if(0=0) condition is satisfied. Hence the output is "Got it".

8

Point out the error in the following program.

#include < stdio . h >int main()
{
    fprintf("Ambition Box");
    printf("%.ef", 2.0);
    return0;
}
a

Error: unknown value in printf() statement.

b

Error: in fprintf() statement.

c

No error and prints "Ambition Box"

d

No error and prints "2.0"

correct answer b
Answer :

Option B

Explanation :

Declaration Syntax:
int fprintf (FILE *stream, const char *format [, argument, ...]);

Example:
fprintf(filestream, "%s %d %s", Name, Age, City);

9

Point out the error in the following program.

#include < stdio . h >#include < string . h >int main()
{
    char str1[] = "Learn through Ambition Box\0.com",  str2[120];
    char *p;
    p = (char*) memccpy(str2, str1, 'i', strlen(str1));
    *p = '\0';
    printf("%s", str2);
    return0;
}
a

Error: in memccpy statement

b

Error: invalid pointer conversion

c

Error: invalid variable declaration

d

No error and prints "Learn through Ambi"

correct answer d
Answer :

Option D

Explanation :

Declaration:
void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest With memccpy(), the copying stops as soon as either of the following occurs:
=> the character 'i' is first copied into str2
=> n bytes have been copied into str2

10

Point out the error in the following program.

#include < stdio . h >int main()
{
    char str[] = "Ambition box";
    printf("%.#s %2s", str, str);
    return0;
}
a

Error: in Array declaration

b

Error: printf statement

c

Error: unspecified character in printf

d

No error

correct answer d
Answer :

Option D

Select a company to compare with

vs

Similar Companies