a=(1,2,3);
b=1,2,3;
c=1,(2,3);
d=(1,2),3;
what's the value of 'a','b','c','d'

Answers were Sorted based on User's Feedback



a=(1,2,3); b=1,2,3; c=1,(2,3); d=(1,2),3; what's the value of 'a','b',&..

Answer / vadivelt

3 1 1 2.

To analyse, lets rewrite the prgm.

#include<stdio.h>
#include<conio.h>
main()
{
int a, b, c, d;
a = (1,2,3);
b = 1,2,3;
c = 1,(2,3);
d = (1,2),3;
printf("%d %d %d %d", a, b, c, d);
getch();
}


Note:Precedence of evaluation of the statements would be:
for (1,2,3) it is -> ie., left to right
for 1,2,3 it is <- ie., right to left.

Now,
1. In statement a = (1,2,3); due to the precedence(->)
latest vale of a would be 3.

2. In the same way( <- ) in the statement b = 1,2,3; latest
value of b would be 1.

In statement c = 1,(2,3); and d = (1,2),3; there are two
precedency lavel.

Lets analyse.

3.In c = 1,(2,3); As we know the basic rule in C that the
expression in a statement with braces evaluated first. So
the outcome of (2,3) would be 3(cos., ->), then the
statement c = 1,(2,3); shall be replaced as c = 1, 3; in
runtime. So in the next execution c's latest value would be
1. Cos now precedence would be <-.

4. In the same way, first d = (1,2),3; will be replaced as
d = 2,3 then d holds the value 2 as latest value.

Is This Answer Correct ?    11 Yes 0 No

a=(1,2,3); b=1,2,3; c=1,(2,3); d=(1,2),3; what's the value of 'a','b',&..

Answer / srsabariselvan3

a=3
b=1
c=1
d=2

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Interview Questions

#include<stdio.h> int SumElement(int *,int); void main(void) { int x[10]; int i=10; for(;i;) { i--; *(x+i)=i; } printf("%d",SumElement(x,10)); } int SumElement(int array[],int size) { int i=0; float sum=0; for(;i<size;i++) sum+=array[i]; return sum; } output?

5 Answers   Ramco,


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

0 Answers  


9.how do you write a function that takes a variable number of arguments? What is the prototype of printf () function? 10.How do you access command-line arguments? 11.what does ‘#include<stdio.h>’ mean? 12.what is the difference between #include<> and #include”…”? 13.what are # pragma staments? 14.what is the most appropriate way to write a multi-statement macro?

4 Answers   L&T,


#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Find the output

5 Answers   CitiGroup,


what does ‘segmentation violation’ mean?

1 Answers  






What is logical error?

0 Answers  


Is it better to use malloc() or calloc()?

0 Answers   Aspire, Infogain,


What is declaration and definition in c?

0 Answers  


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 .

1 Answers   Subex,


What kind of structure is a house?

0 Answers  


List the difference between a While & Do While loops?

0 Answers   Accenture,


What does static mean in c?

1 Answers  


Categories