Apply for Zend Framework Certification Training

c

< Order of Precedence in C Loops in C >




C Operator Precedence Quiz
Instructions: Choose the correct output for each question. Answers and explanations are provided below.
Questions
1. Arithmetic Precedence
What is the output?
#include <stdio.h>
int main(){
    int result = 10 + 5 * 2;
    printf("%d", result);
    return 0;
}
A) 30
B) 20
C) 25
D) 15
2. Division and Modulus
What is the output?
#include <stdio.h>
int main(){
    int result = 20 / 3 + 5 % 2;
    printf("%d", result);
    return 0;
}
A) 7
B) 6
C) 8
D) 5
3. Parentheses
What is the output?
#include <stdio.h>
int main(){
    int result = (10 + 5) * 2 - 4;
    printf("%d", result);
    return 0;
}
A) 26
B) 30
C) 22
D) 18
4. Relational and Logical Operators
What is the output?
#include <stdio.h>
int main(){
    int result = 5 + 3 > 6 && 2 < 4;
    printf("%d", result);
    return 0;
}
A) 0
B) 1
C) 8
D) 4
5. Logical AND and OR
What is the output?
#include <stdio.h>
int main(){
    int result = 0 || 1 && 0 || 1;
    printf("%d", result);
    return 0;
}
A) 0
B) 1
C) 2
D) Compilation error
6. Assignment Associativity
What is the output?
#include <stdio.h>
int main(){
    int a, b, c;
    a = b = c = 5 + 2;
    printf("%d %d %d", a, b, c);
    return 0;
}
A) 5 5 5
B) 7 7 7
C) 7 5 2
D) 2 2 2
7. Increment and Arithmetic
What is the output?
#include <stdio.h>
int main(){
    int a = 5;
    int result = ++a * 2 + 3;
    printf("%d %d", a, result);
    return 0;
}
A) 5 13
B) 6 15
C) 6 13
D) 7 17
8. Bitwise and Equality Operators
What is the output?
#include <stdio.h>
int main(){
    int result = 4 & 2 == 0;
    printf("%d", result);
    return 0;
}
A) 0
B) 1
C) 2
D) 4
9. Conditional Operator
What is the output?
#include <stdio.h>
int main(){
    int a = 8, b = 12;
    int result = a > b ? a + 2 : b + 2;
    printf("%d", result);
    return 0;
}
A) 10
B) 12
C) 14
D) 22
10. Mixed Operators
What is the output?
#include <stdio.h>
int main(){
    int result = 20 - 6 / 2 + 3 * 4;
    printf("%d", result);
    return 0;
}
A) 23
B) 26
C) 29
D) 17

< Order of Precedence in C Loops in C >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top