what is the value of b
if a=5;
b=++a + ++a
Answers were Sorted based on User's Feedback
Answer / raman
ans would be 14
because...
if u dont believe tn run the program
u'll understand
Is This Answer Correct ? | 5 Yes | 3 No |
Answer / shashikanth
if a=5;
b=++a+++a;
initial value a=5
first prefix 6
second prefix 7
final value b=7+7
b=14
ans 14
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / rd
its 13
initial value: 5
++a : 6
again (++a): 7
so it is (7+6) 13...and there shouldn't be any doubt about it.
Is This Answer Correct ? | 14 Yes | 14 No |
Answer / sandeep
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a=5,b;
if(a==5)
{
b=++a + ++a;
Console.WriteLine(b);
Console.ReadLine();
}
}
}
}
answer is 13
Is This Answer Correct ? | 0 Yes | 0 No |
The output will be 14.
i.e. The the value of b is 14.
Explanation:
Consider Expression (b = ++a + ++a;)
Initially the value of a is 5. After the first pre increment operator it will be 6 and after second one it becomes 7. So we guess the expression evaluated as (b = 6 + 7 i.e. b = 13). But wait... In C Programming Language ++a is nothing but a = a + 1, am I right? Ofcourse it's right. Now consider the presedense of pre increment operator over addition operator, Compiler first's evaluate both ++a and the perform addition. So first ++a evaluated to 6 i.e. Now a = 6 then second ++a evaluated as 7 i.e. Now a = 7 and overwrite the old value of a. So compiler evaluated our expression as
b = (a = a +1) + (a = a+1); first compiler assign a = 6 and then a = 7 so our expression becomes b = 7 + 7 as same variable can't holds two different values at a time. And finally our main out will be 14.
I hope now you understand it.
Thnk you!
Is This Answer Correct ? | 0 Yes | 0 No |
Can anyone help me with this please? Need to print the below values.. Thanks 1 1 2 1 2 3 1 2 3 4
if we take a number as a char then can we manipulate(add, subtract) on this number
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
What is the size of structure in c?
What is pivot in c?
write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables
Where are the auto variables stored?
implement general tree using link list
write a C program : To find out the number of identical words in two files . the file name should be taken as command line argument .
What’s a signal? Explain what do I use signals for?
Why isn't any of this standardized in c? Any real program has to do some of these things.
input any 4 digit number and find the difference of all the digits?