Saturday, December 28, 2024
Google search engine
HomeGuest BlogsOutput of C programs | Set 43

Output of C programs | Set 43

1. What is the output of following program?




#include <stdio.h>
int main()
{
    int a = 1, b = 2, c = 3;
    c = a == b;
    printf("%d", c);
    return 0;
}


Choose the correct answer:
(A) 0
(B) 1
(C) 2
(D) 3

Answer : (A)

Explanation :
“==” is relational operator which returns only two values, either 0 or 1.
0: If a == b is false
1: If a == b is true
Since
a=1
b=2
So, a == b is false hence C = 0.

2. What is the output of following program?




#include <stdio.h>
int main()
{
    int a = 20;
    ;
    ;
    printf("%d", a);
    ;
    return 0;
}


Choose the correct answer:
(A) 20
(B) Error
(C) ;20;
(D) ;20

Answer : (A)

Explanation : ; (statement terminator) and no expression/statement is available here, so this is a null statement has no side effect, hence no error is occurred.

3. What is the output of following program?




#include <stdio.h>
int main()
{
    int a = 15;
    float b = 1.234;
    printf("%*f", a, b);
    return 0;
}


Choose the correct answer:

(A) 1.234
(B) 1.234000
(C) Compilation Error
(D) Runtime error

Answer : (B)

Explanation : You can define width formatting at run time using %*, This is known as Indirect width precision. printf(“%*f”, a, b); is considered as “%15f”, hence value of b is printed with left padding by 15.

4. What is the output of following program?




#include <stdio.h>
void main()
{
    int a = 1, b = 2, c = 3;
    char d = 0;
    if (a, b, c, d)
    {
        printf("EXAM");
    }
}


Choose the correct answer:
(A) No Output and No Error
(B) EXAM
(C) Run time error
(D) Compile time error

Answer : (A)

Explanation :Print statement will not execute because ‘ if ‘condition return false. Value of variable d is 0.

5. What is the output of following program?




#include <stdio.h>
void main()
{
    int a = 25;
  
    printf("%o %x", a, a);
    getch();
}


Choose the correct answer:
(A) 25 25
(B) 025 0x25
(C) 12 42
(D) 31 19
(E) None of these

Answer : (D)

Explanation :
%o is used to print the number in octal number format.
%x is used to print the number in hexadecimal number format.
Note: In c octal number starts with 0 and hexadecimal number starts with 0x.

Last Updated :
28 Aug, 2017
Like Article
Save Article


Previous

<!–

8 Min Read | Java

–>


Next


<!–

8 Min Read | Java

–>

Share your thoughts in the comments

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments