what is the value of b
if a=5;
b=++a + ++a
Answers were Sorted based on User's Feedback
Answer / sagar
here in b=++a + ++a;
a
Initial Value 5
First Prefix 6
Second Prefix 7
Final Equation b = 7 + 7 = 14...
So,correct answer is 14....
if the equation was as below:
c=++a;//a==6
d=++a;//a=7
b=c+d;//b=6+7=13
then b==13...
Is This Answer Correct ? | 96 Yes | 29 No |
Answer / madhu cherukuri
a=5
b=++a +++a;
ANS:14
in this case the data will be storing in CPU register so the
result is 14 only.
volatile int a=5;
b=++a + ++a;
ANS:13
the data will be stored in directly memory
Is This Answer Correct ? | 33 Yes | 15 No |
Answer / naresh
Not a very tough question. Important thing to note that in
any expression pre increment operator has a higher prority
than arithemetic operator as a result value of a is
increment is first two times then value of b is evaluated.
So b = 7*7 = 14.
in first ++a we get a=6
in next ++a we get a=7
and b=7+7=14
This question will result in same output for most of the
compilers, but some rare compiler may produce an entire
diffrenent parse tree resulting in an undefined result
Is This Answer Correct ? | 28 Yes | 13 No |
Answer / anup dixit
13 is the correct answers. I'm attaching here a small java
program which proves this:
The program is:
------------------------------------------------------------
public class TestAddition
{
public static void main(String[] args)
{
int a=5;
System.out.println("1..Before a was : "+a);
int b = ++a + ++a;
System.out.println("Final a was : "+a+ ", int b =
++a + ++a is: "+b);
a=5;
System.out.println("2..Before a was : "+a);
int c= ++a+(++a);
System.out.println("Final a was : "+a+", int c=
++a+(++a) is: "+c);
}
}
------------------------------------------------------------
The output is:
------------------------------------------------------------
1..Before a was : 5
Final a was : 7, int b = ++a + ++a is: 13
2..Before a was : 5
Final a was : 7, int c= ++a+(++a) is: 13
Is This Answer Correct ? | 15 Yes | 10 No |
Answer / kaps
IT is defenetly 14...Ans = 14
Explanation:
Because ++a = 6
then again ++a = 7
Now compiler replace the both value with 7 (because of both
are of value of a).
So 7+7 = 14.
It is tested on turbo C...
try with adding one more ++a will give u ans 24(8+8+8) for
++a + ++a + ++a.
Is This Answer Correct ? | 8 Yes | 3 No |
Binary tree traversing
what is the use of ‘auto’ keyword?
can we declare a function in side the structure?
what is difference between ++(*p) and (*p)++
17 Answers Accenture, HCL, IBM,
What is volatile c?
what is the difference between declaration and definition of a variable or function ?
I need testPalindrome and removeSpace #include <stdio.h> #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, ©Count); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }
3. When do you say that a digraph is acyclic A)if and only if its first search does not have back arcs B)a digraph is acyclic if and only if its first search does not have back vertices C)if and only if its first search does not have same dfnumber D)None of these
In which area global, external variables are stored?
write a program to print the one dimensional array.
Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;