C Programming Test And Answer 09

1.What will be the output of the program?

#include<stdio.h>
int main()
{
    char ch;
    if(ch = printf(""))
        printf("It matters\n");
    else
        printf("It doesn't matters\n");
    return 0;
}

A. It matters
B. It doesn’t matters
C. matters
D. No output

Explanation:

printf() returns the number of charecters printed on the console.

Step 1: if(ch = printf("")) here printf() does not print anything, so it returns ‘0’(zero).
Step 2: if(ch = 0) here variable ch has the value ‘0’(zero).
Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.
Hence the output is “It doesn’t matters”.

2.What will be the output of the program ?

#include<stdio.h>
int main()
{
    union var
    {
        int a, b;
    };
    union var v;
    v.a=10;
    v.b=20;
    printf("%d\n", v.a);
    return 0;
}

A. 10
B. 20
C. 30
D. 0

Explanation:
Because union can initialize only one variable at a time. It overwrites the memory with binary value of 20 where it was initialized with binary value of 10 before.

It takes the last initialized value of its member variables.

3.In which order do the following gets evaluated

  1. Relational
  2. Arithmetic
  3. Logical
  4. Assignment

A. 2134
B. 1234
C. 4321
D. 3214

Explanation:

  1. Arithmetic operators: *, /, %, +, -
  2. Relational operators: >, <, >=, <=, ==, !=
  3. Logical operators : !, &&, ||
  4. Assignment operators: =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值