C Programming :: Arrays - Discussion
Home > C Programming > Arrays > MCQs Questions Discussion
8 / 55
What will be output of the following "c" code?
#include<stdio.h>
int main(){
int arr[]={6,12,18,24};
int x=0;
x=arr[1]+(arr[1]=2);
printf("%d",x); return 0;
}
#include<stdio.h>
int main(){
int arr[]={6,12,18,24};
int x=0;
x=arr[1]+(arr[1]=2);
printf("%d",x); return 0;
}
A4
B8
C14
D14
ECompilation error
Answer: Option (Login/Signup)
Show Explanation
x=arr[1]+(arr[1]=2); arr[1] gets modified here itself.
So, 4 will be printed.
Asked In ::
STEP-BY-STEP
when + operator is used it is right associative hence arr[1] = 12 will first be added and then arr[1] will be updated to 2
so, x will be x = (12 + 2)
hence, 14 is printed.
Read Full Answer
Report Error
Please Login First Click Here
TRICK
x=arr[1]+(arr[1]=2); arr[1] gets modified here itself.
So, 4 will be printed.
Read Full Answer
Report Error
Please Login First Click Here