AmbitionBox

Discover Best Places to work in India

C Programming

C Programming Questions and Answers

Showing 71 - 80 of 103 questions

71

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".

72

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);

73

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

74

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

75

How many times "Ambition Box" is get printed?

#includeint main()
{
    int x;
    for(x=-1; x<=10; x++)
    {
        if(x < 5)
            continue;
        elsebreak;
        printf("Ambition Box");
    }
    return0;
}
a

Infinite times

b

11 times

c

0 times

d

10 times

correct answer c
Answer :

Option C

76

How many times the while loop will get executed if a short int is 2 byte wide?

#includeint main()
{
    int j=1;
    while(j <= 255)
    {
        printf("%c %d\n", j, j);
        j++;
    }
    return0;
}
a

Infinite times

b

255 times

c

256 times

d

254 times

correct answer b

Answer :

Option B

Explanation :

 

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.

77

Which of the following is not logical operator?

a

&

b

&&

c

||

d

!

correct answer a

Answer :

Option A

Explanation :

Bitwise operators: & is a Bitwise AND operator. Logical operators: && is a Logical AND operator. || is a Logical OR operator. ! is a NOT operator. So, '&' is not a Logical operator.

78

In mathematics and computer programming, which is the correct order of mathematical operators ?

a

Addition, Subtraction, Multiplication, Division

b

Division, Multiplication, Addition, Subtraction

c

Multiplication, Addition, Division, Subtraction

d

Addition, Division, Modulus, Subtraction

correct answer b

Answer :

Option B

Explanation :

Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction). Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.

79

What will be the output of the program?

#include<stdio.h>int main()
{
    int a = 500, b = 100, c;
    if(!a >= 400)
        b = 300;
    c = 200;
    printf("b = %d c = %d\n", b, c);
    return0;
}
a

b = 300 c = 200

b

b = 100 c = garbage

c

b = 300 c = garbage

d

b = 100 c = 200

correct answer d

Answer :

Option D

Explanation :

Initially variables a = 500, b = 100 and c is not assigned.
Step 1: if(!a >= 400)
Step 2: if(!500 >= 400)
Step 3: if(0 >= 400)
Step 4: if(FALSE) Hence the if condition is failed.
Step 5: So, variable c is assigned to a value '200'.
Step 6: printf("b = %d c = %d\n", b, c); It prints value of b and c.
Hence the output is "b = 100 c = 200"

80

What will be the output of the program?

#include<stdio.h>int main()
{
    unsignedint i = 65535; /* Assume 2 byte integer*/while(i++ != 0)
        printf("%d",++i);
    printf("\n");
    return0;
}
a

Infinite loop  

b

0 1 2 ... 65535

c

0 1 2 ... 32767 - 32766 -32765 -1 0

d

No output

correct answer a

Answer :

Option A

Explanation :

Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535.

Step 1:unsigned int i = 65535;
Step 2:
Loop 1: while(i++ != 0) this statement becomes while(65535 != 0). Hence the while(TRUE) condition is satisfied. Then the printf("%d", ++i); prints '1'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement) Loop 2: while(i++ != 0) this statement becomes while(1 != 0). Hence the while(TRUE) condition is satisfied. Then the printf("%d", ++i); prints '3'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement)
....

The while loop will never stops executing, because variable i will never become '0'(zero). Hence it is an 'Infinite loop'.

Select a company to compare with

vs

Similar Companies