Re: [algogeeks] c output .. help plz

2011-09-06 Thread sukran dhawan
coz both floating point are stored in ieee format which is different from
integers

On Tue, Sep 6, 2011 at 10:18 PM, sukran dhawan wrote:

> it wil not truncate the floating point to integer remember...
>
>
> On Tue, Sep 6, 2011 at 9:55 PM, sivaviknesh s wrote:
>
>> printf("%d",3.14*6.25*6.25);
>>
>> ...ans : 0 ..how and why?? why not type conversion take place??
>>
>> --
>> Regards,
>> $iva
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c output .. help plz

2011-09-06 Thread sukran dhawan
it wil not truncate the floating point to integer remember...

On Tue, Sep 6, 2011 at 9:55 PM, sivaviknesh s wrote:

> printf("%d",3.14*6.25*6.25);
>
> ...ans : 0 ..how and why?? why not type conversion take place??
>
> --
> Regards,
> $iva
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] c output .. help plz

2011-09-06 Thread sivaviknesh s
 printf("%d",3.14*6.25*6.25);

...ans : 0 ..how and why?? why not type conversion take place??

-- 
Regards,
$iva

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-22 Thread Interstellar Overdrive
@nicks- Dev-cpp supports gcc compilers only. Just saying

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/tpDu2bt_tG8J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-14 Thread T3rminal
1)
getchar must be a function in that case . Check /usr/include/stdio.h . It 
must have contained an extern definition (it is on my machine).

2)
Machines generally have separate registers for floating point values(let say 
%fr). While executing this line *printf("%d\n",t); *that register is loaded 
with the value of* "t" *but this call to printf will not access it because 
of* "%d" *specifier* . *Since then the value in this register has not been 
replaced, therefore call to printf with* "%f" *specifier will access* %fr 
*register 
and print its value.*
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/c88zZWRmRvIJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-13 Thread sagar pareek
@sandeep
+1 for your answer of question 2 :)

On Tue, Jul 12, 2011 at 8:57 AM, Sandeep Jain  wrote:

> I'll put it in simple words, when printf is executed, it expects the
> arguments to be of the same type and in the same order as they appear in the
> format string.
> Otherwise, it starts to exhibit random behavior whenever a first mismatch
> occurs.
>
>
> Regards,
> Sandeep Jain
>
>
>
>
> On Tue, Jul 12, 2011 at 1:32 AM, nicks  wrote:
>
>> @sandeep u mean whenever printf will demand for %f then it will print
>> 2.0.is it random behavior or always going to happen ??
>>
>> anyone else having better idea regarding 1st and 2nd problem...
>>
>> On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain wrote:
>>
>>> TurboC has many flaws, one of the simplest examples would be
>>> char *p;
>>> scanf("%s", p);
>>>
>>> In gcc/g++ this will surely lead to segmentation fault as memory has not
>>> been allocated. Whereas in TC it will execute fine in most of the cases.
>>> Infact this will crash when your code is really large.
>>>
>>> As for input, 2 will automatically be treated as 2.0 when scanf demands a
>>> floating value. However, if you enter characters in place of numbers or vice
>>> versa. You may experience weird behavior.
>>>
>>>
>>>
>>>
>>> Regards,
>>> Sandeep Jain
>>>
>>>
>>>
>>>
>>> On Mon, Jul 11, 2011 at 9:37 AM, nicks wrote:
>>>
 @sandeep,kamakshiithanks both...your replies were really
 helpfuli understood my fault in 3,4,5...they are clea now..but i am
 still stuck with problem 1 and 2

 @sandeepwhat if i am using turbo C...though i am using gcc on
 terminal in my linux system.
 moreover acc. t K&R "printf uses it's first argument to decide how many
 arguments follow and what their types are. it will get confused,and you 
 will
 get wrong answers,if there are not enough arguments or if they are the 
 wrong
 type"
 it's fine it will give the wrong answer then it's only the value we
 provide in input ???


 @kamakshii...can explain your point related to macro in detail.is it
 related to linking or something which is done after creating object file...

 On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal <
 kamakshi...@gmail.com> wrote:

> probelm 5:It must be giving runtime error not segmentation fault coz it
> is an infinite recursion
>
>
> On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal <
> kamakshi...@gmail.com> wrote:
>
>> for the first question...it will take #ifdef getchar to be '1' only
>> when it is defined as a MACRO in your program..if u dont define macro it
>> will not take it into consideration even if it is defined in header file.
>>
>> On Mon, Jul 11, 2011 at 12:38 AM, nicks 
>> wrote:
>>
>>> Someone please help me in understanding the following output -
>>>
>>> Problem *1>.*
>>> #include
>>> #ifdef getchar //this expression is evaluated to zero.why
>>> is so happening ??getchar is defined as macro in stdio.h.i 
>>> mean
>>> else part shouldn't be executed which is happening
>>> #undef getchar
>>> #else
>>> #define getchar scanf("%c",&ch);
>>> #endif
>>> main()
>>> {
>>> char ch;
>>>  int c;
>>> c=getchar;
>>> printf("%d",c);
>>> }
>>>
>>> *OUTPUT-  1*
>>> *
>>> *
>>> *
>>> *
>>> *2>.*
>>> #include
>>> void main()
>>> {
>>> long x;
>>>  float t;
>>> scanf("%f",&t);
>>> printf("%d\n",t);
>>>  x=90;
>>> printf("%ld\n",x);
>>> {
>>>  x=1;
>>> printf("%f\n",x);
>>> {
>>>  x=30;
>>> printf("%f\n",x);
>>> }
>>>  printf("%f\n",x);
>>> }
>>> x==9;
>>>  printf("%f\n",x);
>>> }
>>>
>>> *OUTPUT(INPUT IS 2) -*
>>> *2*
>>> *0*
>>> *90*
>>> *2.00*
>>> *2.00*
>>> *2.00*
>>> *2.00*
>>> *
>>> *
>>> In this problem i failed to Understand why t is printed as 0 (though
>>> float is converted to integer by truncation of the fractional part)
>>> and how the value of t is transferred to xlooks very strange to
>>> me !!
>>>
>>>
>>> *3>.*
>>> #include
>>> main()
>>> {
>>> printf("\nACM-CIC"+3);
>>> printf(4+"\nACM-CIC");
>>>
>>> }
>>>
>>> *OUTPUT -*
>>> *M-CIC-CIC*
>>> *
>>> *
>>> What does +3 and +4 doing and does it matter to use them before the
>>> format string or after it ??
>>>
>>> *4>.*
>>> #include
>>> main()
>>> {
>>> long long i=50;
>>> i==1000;
>>>  printf("i=%d\n\n%lld",sizeof(i),i);
>>> //system("pause");
>>> }
>>>
>>> *OUTPUT -*
>>> *i=8*
>>> *
>>> *
>>> *50*
>>> *
>>> *
>>> Assigning very large value to i isn't changing it's value.why is
>>> so happenin

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread nicks
3 1 is the output which i predicted without running...it is giving 3 3
on gcc and may give 3 2 on dev c++ . output will be compiler dependent
as these types of situations are not defined in standards hence
implementation dependent..i want someone to explain the output with
reference to standard gcc compiler.

On Tue, Jul 12, 2011 at 6:16 PM, Kamakshii Aggarwal
wrote:

> for the second problem,y should the answer be 3 1?.it should be 3 2
> and it is working fine on dev c++ giving 3 2.
>
>
> On Tue, Jul 12, 2011 at 2:48 PM, Anand Saha  wrote:
>
>>
>>
>> On Tue, Jul 12, 2011 at 2:36 PM, nicks wrote:
>>>
>>> and in problem 3 what i understood after reading with what you wrote is
>>> that size of tag will remain sizeof(int) irrespective of the number of
>>> constants in it.correct me if i am wrong !!
>>>
>>>
>> Right.
>>
>> --
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Kamakshi
> kamakshi...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Kamakshii Aggarwal
for the second problem,y should the answer be 3 1?.it should be 3 2
and it is working fine on dev c++ giving 3 2.

On Tue, Jul 12, 2011 at 2:48 PM, Anand Saha  wrote:

>
>
> On Tue, Jul 12, 2011 at 2:36 PM, nicks  wrote:
>>
>> and in problem 3 what i understood after reading with what you wrote is
>> that size of tag will remain sizeof(int) irrespective of the number of
>> constants in it.correct me if i am wrong !!
>>
>>
> Right.
>
> --
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards,
Kamakshi
kamakshi...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Anand Saha
On Tue, Jul 12, 2011 at 2:36 PM, nicks  wrote:
>
> and in problem 3 what i understood after reading with what you wrote is
> that size of tag will remain sizeof(int) irrespective of the number of
> constants in it.correct me if i am wrong !!
>
>
Right.

--

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread nicks
@anandregarding problem 2 i agree with you and observed the samebut
that gives me the feel that the compiler in working in the interprating
manner though it doesn't...btw thanks for pointing it out.

and in problem 3 what i understood after reading with what you wrote is that
size of tag will remain sizeof(int) irrespective of the number of constants
in it.correct me if i am wrong !!
On Tue, Jul 12, 2011 at 2:20 PM, Anand Saha  wrote:

>
> On Tue, Jul 12, 2011 at 1:29 AM, nicks  wrote:
>
>>
>> *PROBLEM 3>.*
>> *
>> *
>> #include
>> main()
>> {
>> enum {low='a',high='b'}tag;
>>  char try=low;
>> printf("Size=%d",sizeof(tag));
>> switch (try)
>>  {
>> case 'a':printf("aaa");break;
>> case 'b':printf("bbb");
>>  case 'c':printf("ccc");
>> }
>> //system("pause");
>> }
>>
>> in this program size of enum comes out to be 4..help me in understanding
>> the size of enum...how it is stored in memory??...does the size of enum
>> depend on number of constant in it ?anyone link regarding that ??
>>
>>
>
> What will be interesting to see here is:
>
> printf 
> ("Size = 
> %d\n",sizeof(tag));printf 
> ("Size = 
> %d\n",sizeof(low));
>
>
> We will get 4 and 4.  'tag' is the optional identifier, 'low' is an
> enumerated type.
>
> From C99,
>
> for tag: "The expression that defines the value of an enumeration constant
> shall be an integer constant expression that has a value representable as an
> int."
>
> for low: "Each enumerated type shall be compatible with char, a signed
> integer type, or an unsigned integer type. The choice of type is
> implementation-defined, but shall be capable of representing the values of
> all the members of the enumeration. The enumerated type is incomplete until
> after the } that terminates the list of enumerator declarations."
>
> PS: I didn't know the exact constraints too, thanks to nicks for bringing
> up this question.
> --
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Anand Saha
On Tue, Jul 12, 2011 at 1:29 AM, nicks  wrote:

>
> *PROBLEM 3>.*
> *
> *
> #include
> main()
> {
> enum {low='a',high='b'}tag;
>  char try=low;
> printf("Size=%d",sizeof(tag));
> switch (try)
>  {
> case 'a':printf("aaa");break;
> case 'b':printf("bbb");
>  case 'c':printf("ccc");
> }
> //system("pause");
> }
>
> in this program size of enum comes out to be 4..help me in understanding
> the size of enum...how it is stored in memory??...does the size of enum
> depend on number of constant in it ?anyone link regarding that ??
>
>

What will be interesting to see here is:

printf 
("Size
= %d\n",sizeof(tag));printf
("Size
= %d\n",sizeof(low));


We will get 4 and 4.  'tag' is the optional identifier, 'low' is an
enumerated type.

>From C99,

for tag: "The expression that defines the value of an enumeration constant
shall be an integer constant expression that has a value representable as an
int."

for low: "Each enumerated type shall be compatible with char, a signed
integer type, or an unsigned integer type. The choice of type is
implementation-defined, but shall be capable of representing the values of
all the members of the enumeration. The enumerated type is incomplete until
after the } that terminates the list of enumerator declarations."

PS: I didn't know the exact constraints too, thanks to nicks for bringing up
this question.
--

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread Sandeep Jain
I'll put it in simple words, when printf is executed, it expects the
arguments to be of the same type and in the same order as they appear in the
format string.
Otherwise, it starts to exhibit random behavior whenever a first mismatch
occurs.


Regards,
Sandeep Jain



On Tue, Jul 12, 2011 at 1:32 AM, nicks  wrote:

> @sandeep u mean whenever printf will demand for %f then it will print
> 2.0.is it random behavior or always going to happen ??
>
> anyone else having better idea regarding 1st and 2nd problem...
>
> On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain wrote:
>
>> TurboC has many flaws, one of the simplest examples would be
>> char *p;
>> scanf("%s", p);
>>
>> In gcc/g++ this will surely lead to segmentation fault as memory has not
>> been allocated. Whereas in TC it will execute fine in most of the cases.
>> Infact this will crash when your code is really large.
>>
>> As for input, 2 will automatically be treated as 2.0 when scanf demands a
>> floating value. However, if you enter characters in place of numbers or vice
>> versa. You may experience weird behavior.
>>
>>
>>
>>
>> Regards,
>> Sandeep Jain
>>
>>
>>
>>
>> On Mon, Jul 11, 2011 at 9:37 AM, nicks wrote:
>>
>>> @sandeep,kamakshiithanks both...your replies were really helpfuli
>>> understood my fault in 3,4,5...they are clea now..but i am still stuck
>>> with problem 1 and 2
>>>
>>> @sandeepwhat if i am using turbo C...though i am using gcc on
>>> terminal in my linux system.
>>> moreover acc. t K&R "printf uses it's first argument to decide how many
>>> arguments follow and what their types are. it will get confused,and you will
>>> get wrong answers,if there are not enough arguments or if they are the wrong
>>> type"
>>> it's fine it will give the wrong answer then it's only the value we
>>> provide in input ???
>>>
>>>
>>> @kamakshii...can explain your point related to macro in detail.is it
>>> related to linking or something which is done after creating object file...
>>>
>>> On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal <
>>> kamakshi...@gmail.com> wrote:
>>>
 probelm 5:It must be giving runtime error not segmentation fault coz it
 is an infinite recursion


 On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal <
 kamakshi...@gmail.com> wrote:

> for the first question...it will take #ifdef getchar to be '1' only
> when it is defined as a MACRO in your program..if u dont define macro it
> will not take it into consideration even if it is defined in header file.
>
> On Mon, Jul 11, 2011 at 12:38 AM, nicks wrote:
>
>> Someone please help me in understanding the following output -
>>
>> Problem *1>.*
>> #include
>> #ifdef getchar //this expression is evaluated to zero.why
>> is so happening ??getchar is defined as macro in stdio.h.i 
>> mean
>> else part shouldn't be executed which is happening
>> #undef getchar
>> #else
>> #define getchar scanf("%c",&ch);
>> #endif
>> main()
>> {
>> char ch;
>>  int c;
>> c=getchar;
>> printf("%d",c);
>> }
>>
>> *OUTPUT-  1*
>> *
>> *
>> *
>> *
>> *2>.*
>> #include
>> void main()
>> {
>> long x;
>>  float t;
>> scanf("%f",&t);
>> printf("%d\n",t);
>>  x=90;
>> printf("%ld\n",x);
>> {
>>  x=1;
>> printf("%f\n",x);
>> {
>>  x=30;
>> printf("%f\n",x);
>> }
>>  printf("%f\n",x);
>> }
>> x==9;
>>  printf("%f\n",x);
>> }
>>
>> *OUTPUT(INPUT IS 2) -*
>> *2*
>> *0*
>> *90*
>> *2.00*
>> *2.00*
>> *2.00*
>> *2.00*
>> *
>> *
>> In this problem i failed to Understand why t is printed as 0 (though
>> float is converted to integer by truncation of the fractional part)
>> and how the value of t is transferred to xlooks very strange to me
>> !!
>>
>>
>> *3>.*
>> #include
>> main()
>> {
>> printf("\nACM-CIC"+3);
>> printf(4+"\nACM-CIC");
>>
>> }
>>
>> *OUTPUT -*
>> *M-CIC-CIC*
>> *
>> *
>> What does +3 and +4 doing and does it matter to use them before the
>> format string or after it ??
>>
>> *4>.*
>> #include
>> main()
>> {
>> long long i=50;
>> i==1000;
>>  printf("i=%d\n\n%lld",sizeof(i),i);
>> //system("pause");
>> }
>>
>> *OUTPUT -*
>> *i=8*
>> *
>> *
>> *50*
>> *
>> *
>> Assigning very large value to i isn't changing it's value.why is
>> so happening ??
>>
>> and the last one
>>
>> *5>.*
>> #include
>> main()
>> {
>> static int i=0;
>>  if(i<=-1)
>> printf("\nBull's Eye");
>> else
>>  {
>> main();
>> _exit(1);
>>  }
>> i++;
>> }
>>
>> *OUTPUT -*
>> *segementation fault*
>

Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread oppilas .
> *OUTPUT-*
> 78
> 6
>
> in this problem my problem is using printf and scanf as variable
> names.they are functions in the stdio.h then how are they available for
> variable name ??...generally what happens is that whenever we use some name
> for the function and then use that name for some variable then compiler
> gives error then why in this case error is not coming ??
>
> Think it in terms of global and local reference.
http://ideone.com/u6bQ

> *PROBLEM 2>.*
>
> #include
> main()
> {
> int i=1;
> printf("\n%d %d",i^=1%2,i<<=1%2);  // does it evaluate the final value of i
> before printing ??
> **}
> *OUTPUT-*
> 3 3
>
> In gcc what i have observed is that arguments of printf are evaluated from
> right to left i.e i<<=1%2 is evaluated before i^=1%2...hence i first becomes
> 2 then 3 after XOR with 1now output according to me should be "3
> 1".but what actually is happening is that it us evaluating i and then
> printing it 3 3.can someone explain why this output is coming ?
>
> and the last problem
>
Left to right. Try on ideone.
void P(int a,int b){ printf a b;}
main(){ int x;
P (x++,++x);
print x++,++x
}

>
> *PROBLEM 3>.*
> *
> *
> #include
> main()
> {
> enum {low='a',high='b'}tag;
>  char try=low;
> printf("Size=%d",sizeof(tag));
> switch (try)
>  {
> case 'a':printf("aaa");break;
> case 'b':printf("bbb");
>  case 'c':printf("ccc");
> }
> //system("pause");
> }
>
> in this program size of enum comes out to be 4..help me in understanding
> the size of enum...how it is stored in memory??...does the size of enum
> depend on number of constant in it ?anyone link regarding that ??
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread varun pahwa
problem 3. I think tag is a reference so its size is 4 bytes.

On Tue, Jul 12, 2011 at 1:29 AM, nicks  wrote:

> Guys plz help me in understanding the following output
>
> *PROBLEM 1>.*
> *
> *
> #include
> main()
> {
> int scanf=78;
>  //int printf=45;
> int getchar=6;
> printf("%d",scanf);
>  printf("\n%d",getchar);
> }
>
> *OUTPUT-*
> 78
> 6
>
> in this problem my problem is using printf and scanf as variable
> names.they are functions in the stdio.h then how are they available for
> variable name ??...generally what happens is that whenever we use some name
> for the function and then use that name for some variable then compiler
> gives error then why in this case error is not coming ??
>
> *PROBLEM 2>.*
>
> #include
> main()
> {
> int i=1;
> printf("\n%d %d",i^=1%2,i<<=1%2);  // does it evaluate the final value of i
> before printing ??
> **}
> *OUTPUT-*
> 3 3
>
> In gcc what i have observed is that arguments of printf are evaluated from
> right to left i.e i<<=1%2 is evaluated before i^=1%2...hence i first becomes
> 2 then 3 after XOR with 1now output according to me should be "3
> 1".but what actually is happening is that it us evaluating i and then
> printing it 3 3.can someone explain why this output is coming ?
>
> and the last problem
>
> *PROBLEM 3>.*
> *
> *
> #include
> main()
> {
> enum {low='a',high='b'}tag;
>  char try=low;
> printf("Size=%d",sizeof(tag));
> switch (try)
>  {
> case 'a':printf("aaa");break;
> case 'b':printf("bbb");
>  case 'c':printf("ccc");
> }
> //system("pause");
> }
>
> in this program size of enum comes out to be 4..help me in understanding
> the size of enum...how it is stored in memory??...does the size of enum
> depend on number of constant in it ?anyone link regarding that ??
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-11 Thread nicks
@sandeep u mean whenever printf will demand for %f then it will print
2.0.is it random behavior or always going to happen ??

anyone else having better idea regarding 1st and 2nd problem...

On Mon, Jul 11, 2011 at 9:51 AM, Sandeep Jain  wrote:

> TurboC has many flaws, one of the simplest examples would be
> char *p;
> scanf("%s", p);
>
> In gcc/g++ this will surely lead to segmentation fault as memory has not
> been allocated. Whereas in TC it will execute fine in most of the cases.
> Infact this will crash when your code is really large.
>
> As for input, 2 will automatically be treated as 2.0 when scanf demands a
> floating value. However, if you enter characters in place of numbers or vice
> versa. You may experience weird behavior.
>
>
>
>
> Regards,
> Sandeep Jain
>
>
>
>
> On Mon, Jul 11, 2011 at 9:37 AM, nicks  wrote:
>
>> @sandeep,kamakshiithanks both...your replies were really helpfuli
>> understood my fault in 3,4,5...they are clea now..but i am still stuck
>> with problem 1 and 2
>>
>> @sandeepwhat if i am using turbo C...though i am using gcc on terminal
>> in my linux system.
>> moreover acc. t K&R "printf uses it's first argument to decide how many
>> arguments follow and what their types are. it will get confused,and you will
>> get wrong answers,if there are not enough arguments or if they are the wrong
>> type"
>> it's fine it will give the wrong answer then it's only the value we
>> provide in input ???
>>
>>
>> @kamakshii...can explain your point related to macro in detail.is it
>> related to linking or something which is done after creating object file...
>>
>> On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal <
>> kamakshi...@gmail.com> wrote:
>>
>>> probelm 5:It must be giving runtime error not segmentation fault coz it
>>> is an infinite recursion
>>>
>>>
>>> On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal <
>>> kamakshi...@gmail.com> wrote:
>>>
 for the first question...it will take #ifdef getchar to be '1' only when
 it is defined as a MACRO in your program..if u dont define macro it will 
 not
 take it into consideration even if it is defined in header file.

 On Mon, Jul 11, 2011 at 12:38 AM, nicks wrote:

> Someone please help me in understanding the following output -
>
> Problem *1>.*
> #include
> #ifdef getchar //this expression is evaluated to zero.why
> is so happening ??getchar is defined as macro in stdio.h.i 
> mean
> else part shouldn't be executed which is happening
> #undef getchar
> #else
> #define getchar scanf("%c",&ch);
> #endif
> main()
> {
> char ch;
>  int c;
> c=getchar;
> printf("%d",c);
> }
>
> *OUTPUT-  1*
> *
> *
> *
> *
> *2>.*
> #include
> void main()
> {
> long x;
>  float t;
> scanf("%f",&t);
> printf("%d\n",t);
>  x=90;
> printf("%ld\n",x);
> {
>  x=1;
> printf("%f\n",x);
> {
>  x=30;
> printf("%f\n",x);
> }
>  printf("%f\n",x);
> }
> x==9;
>  printf("%f\n",x);
> }
>
> *OUTPUT(INPUT IS 2) -*
> *2*
> *0*
> *90*
> *2.00*
> *2.00*
> *2.00*
> *2.00*
> *
> *
> In this problem i failed to Understand why t is printed as 0 (though
> float is converted to integer by truncation of the fractional part)
> and how the value of t is transferred to xlooks very strange to me
> !!
>
>
> *3>.*
> #include
> main()
> {
> printf("\nACM-CIC"+3);
> printf(4+"\nACM-CIC");
>
> }
>
> *OUTPUT -*
> *M-CIC-CIC*
> *
> *
> What does +3 and +4 doing and does it matter to use them before the
> format string or after it ??
>
> *4>.*
> #include
> main()
> {
> long long i=50;
> i==1000;
>  printf("i=%d\n\n%lld",sizeof(i),i);
> //system("pause");
> }
>
> *OUTPUT -*
> *i=8*
> *
> *
> *50*
> *
> *
> Assigning very large value to i isn't changing it's value.why is so
> happening ??
>
> and the last one
>
> *5>.*
> #include
> main()
> {
> static int i=0;
>  if(i<=-1)
> printf("\nBull's Eye");
> else
>  {
> main();
> _exit(1);
>  }
> i++;
> }
>
> *OUTPUT -*
> *segementation fault*
> *
> *
> What's Wrong with the above Code due to which it is giving Runtime
> errorplz help me pointing it out !!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.goo

[algogeeks] C OUTPUT HELP

2011-07-11 Thread nicks
Guys plz help me in understanding the following output

*PROBLEM 1>.*
*
*
#include
main()
{
int scanf=78;
//int printf=45;
int getchar=6;
printf("%d",scanf);
printf("\n%d",getchar);
}

*OUTPUT-*
78
6

in this problem my problem is using printf and scanf as variable
names.they are functions in the stdio.h then how are they available for
variable name ??...generally what happens is that whenever we use some name
for the function and then use that name for some variable then compiler
gives error then why in this case error is not coming ??

*PROBLEM 2>.*

#include
main()
{
int i=1;
printf("\n%d %d",i^=1%2,i<<=1%2);  // does it evaluate the final value of i
before printing ??
**}
*OUTPUT-*
3 3

In gcc what i have observed is that arguments of printf are evaluated from
right to left i.e i<<=1%2 is evaluated before i^=1%2...hence i first becomes
2 then 3 after XOR with 1now output according to me should be "3
1".but what actually is happening is that it us evaluating i and then
printing it 3 3.can someone explain why this output is coming ?

and the last problem

*PROBLEM 3>.*
*
*
#include
main()
{
enum {low='a',high='b'}tag;
char try=low;
printf("Size=%d",sizeof(tag));
switch (try)
{
case 'a':printf("aaa");break;
case 'b':printf("bbb");
case 'c':printf("ccc");
}
//system("pause");
}

in this program size of enum comes out to be 4..help me in understanding the
size of enum...how it is stored in memory??...does the size of enum depend
on number of constant in it ?anyone link regarding that ??

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Sandeep Jain
TurboC has many flaws, one of the simplest examples would be
char *p;
scanf("%s", p);

In gcc/g++ this will surely lead to segmentation fault as memory has not
been allocated. Whereas in TC it will execute fine in most of the cases.
Infact this will crash when your code is really large.

As for input, 2 will automatically be treated as 2.0 when scanf demands a
floating value. However, if you enter characters in place of numbers or vice
versa. You may experience weird behavior.




Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 9:37 AM, nicks  wrote:

> @sandeep,kamakshiithanks both...your replies were really helpfuli
> understood my fault in 3,4,5...they are clea now..but i am still stuck
> with problem 1 and 2
>
> @sandeepwhat if i am using turbo C...though i am using gcc on terminal
> in my linux system.
> moreover acc. t K&R "printf uses it's first argument to decide how many
> arguments follow and what their types are. it will get confused,and you will
> get wrong answers,if there are not enough arguments or if they are the wrong
> type"
> it's fine it will give the wrong answer then it's only the value we provide
> in input ???
>
>
> @kamakshii...can explain your point related to macro in detail.is it
> related to linking or something which is done after creating object file...
>
> On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal  > wrote:
>
>> probelm 5:It must be giving runtime error not segmentation fault coz it is
>> an infinite recursion
>>
>>
>> On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal <
>> kamakshi...@gmail.com> wrote:
>>
>>> for the first question...it will take #ifdef getchar to be '1' only when
>>> it is defined as a MACRO in your program..if u dont define macro it will not
>>> take it into consideration even if it is defined in header file.
>>>
>>> On Mon, Jul 11, 2011 at 12:38 AM, nicks wrote:
>>>
 Someone please help me in understanding the following output -

 Problem *1>.*
 #include
 #ifdef getchar //this expression is evaluated to zero.why is
 so happening ??getchar is defined as macro in stdio.h.i mean
 else part shouldn't be executed which is happening
 #undef getchar
 #else
 #define getchar scanf("%c",&ch);
 #endif
 main()
 {
 char ch;
  int c;
 c=getchar;
 printf("%d",c);
 }

 *OUTPUT-  1*
 *
 *
 *
 *
 *2>.*
 #include
 void main()
 {
 long x;
  float t;
 scanf("%f",&t);
 printf("%d\n",t);
  x=90;
 printf("%ld\n",x);
 {
  x=1;
 printf("%f\n",x);
 {
  x=30;
 printf("%f\n",x);
 }
  printf("%f\n",x);
 }
 x==9;
  printf("%f\n",x);
 }

 *OUTPUT(INPUT IS 2) -*
 *2*
 *0*
 *90*
 *2.00*
 *2.00*
 *2.00*
 *2.00*
 *
 *
 In this problem i failed to Understand why t is printed as 0 (though
 float is converted to integer by truncation of the fractional part)
 and how the value of t is transferred to xlooks very strange to me
 !!


 *3>.*
 #include
 main()
 {
 printf("\nACM-CIC"+3);
 printf(4+"\nACM-CIC");

 }

 *OUTPUT -*
 *M-CIC-CIC*
 *
 *
 What does +3 and +4 doing and does it matter to use them before the
 format string or after it ??

 *4>.*
 #include
 main()
 {
 long long i=50;
 i==1000;
  printf("i=%d\n\n%lld",sizeof(i),i);
 //system("pause");
 }

 *OUTPUT -*
 *i=8*
 *
 *
 *50*
 *
 *
 Assigning very large value to i isn't changing it's value.why is so
 happening ??

 and the last one

 *5>.*
 #include
 main()
 {
 static int i=0;
  if(i<=-1)
 printf("\nBull's Eye");
 else
  {
 main();
 _exit(1);
  }
 i++;
 }

 *OUTPUT -*
 *segementation fault*
 *
 *
 What's Wrong with the above Code due to which it is giving Runtime
 errorplz help me pointing it out !!

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Regards,
>>> Kamakshi
>>> kamakshi...@gmail.com
>>>
>>
>>
>>
>> --
>> Regards,
>> Kamakshi
>> kamakshi...@gmail.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group 

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread nicks
@sandeep,kamakshiithanks both...your replies were really helpfuli
understood my fault in 3,4,5...they are clea now..but i am still stuck
with problem 1 and 2

@sandeepwhat if i am using turbo C...though i am using gcc on terminal
in my linux system.
moreover acc. t K&R "printf uses it's first argument to decide how many
arguments follow and what their types are. it will get confused,and you will
get wrong answers,if there are not enough arguments or if they are the wrong
type"
it's fine it will give the wrong answer then it's only the value we provide
in input ???


@kamakshii...can explain your point related to macro in detail.is it
related to linking or something which is done after creating object file...

On Mon, Jul 11, 2011 at 1:37 AM, Kamakshii Aggarwal
wrote:

> probelm 5:It must be giving runtime error not segmentation fault coz it is
> an infinite recursion
>
>
> On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal  > wrote:
>
>> for the first question...it will take #ifdef getchar to be '1' only when
>> it is defined as a MACRO in your program..if u dont define macro it will not
>> take it into consideration even if it is defined in header file.
>>
>> On Mon, Jul 11, 2011 at 12:38 AM, nicks wrote:
>>
>>> Someone please help me in understanding the following output -
>>>
>>> Problem *1>.*
>>> #include
>>> #ifdef getchar //this expression is evaluated to zero.why is
>>> so happening ??getchar is defined as macro in stdio.h.i mean
>>> else part shouldn't be executed which is happening
>>> #undef getchar
>>> #else
>>> #define getchar scanf("%c",&ch);
>>> #endif
>>> main()
>>> {
>>> char ch;
>>>  int c;
>>> c=getchar;
>>> printf("%d",c);
>>> }
>>>
>>> *OUTPUT-  1*
>>> *
>>> *
>>> *
>>> *
>>> *2>.*
>>> #include
>>> void main()
>>> {
>>> long x;
>>>  float t;
>>> scanf("%f",&t);
>>> printf("%d\n",t);
>>>  x=90;
>>> printf("%ld\n",x);
>>> {
>>>  x=1;
>>> printf("%f\n",x);
>>> {
>>>  x=30;
>>> printf("%f\n",x);
>>> }
>>>  printf("%f\n",x);
>>> }
>>> x==9;
>>>  printf("%f\n",x);
>>> }
>>>
>>> *OUTPUT(INPUT IS 2) -*
>>> *2*
>>> *0*
>>> *90*
>>> *2.00*
>>> *2.00*
>>> *2.00*
>>> *2.00*
>>> *
>>> *
>>> In this problem i failed to Understand why t is printed as 0 (though
>>> float is converted to integer by truncation of the fractional part)
>>> and how the value of t is transferred to xlooks very strange to me !!
>>>
>>>
>>> *3>.*
>>> #include
>>> main()
>>> {
>>> printf("\nACM-CIC"+3);
>>> printf(4+"\nACM-CIC");
>>>
>>> }
>>>
>>> *OUTPUT -*
>>> *M-CIC-CIC*
>>> *
>>> *
>>> What does +3 and +4 doing and does it matter to use them before the
>>> format string or after it ??
>>>
>>> *4>.*
>>> #include
>>> main()
>>> {
>>> long long i=50;
>>> i==1000;
>>>  printf("i=%d\n\n%lld",sizeof(i),i);
>>> //system("pause");
>>> }
>>>
>>> *OUTPUT -*
>>> *i=8*
>>> *
>>> *
>>> *50*
>>> *
>>> *
>>> Assigning very large value to i isn't changing it's value.why is so
>>> happening ??
>>>
>>> and the last one
>>>
>>> *5>.*
>>> #include
>>> main()
>>> {
>>> static int i=0;
>>>  if(i<=-1)
>>> printf("\nBull's Eye");
>>> else
>>>  {
>>> main();
>>> _exit(1);
>>>  }
>>> i++;
>>> }
>>>
>>> *OUTPUT -*
>>> *segementation fault*
>>> *
>>> *
>>> What's Wrong with the above Code due to which it is giving Runtime
>>> errorplz help me pointing it out !!
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards,
>> Kamakshi
>> kamakshi...@gmail.com
>>
>
>
>
> --
> Regards,
> Kamakshi
> kamakshi...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Kamakshii Aggarwal
probelm 5:It must be giving runtime error not segmentation fault coz it is
an infinite recursion

On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal
wrote:

> for the first question...it will take #ifdef getchar to be '1' only when it
> is defined as a MACRO in your program..if u dont define macro it will not
> take it into consideration even if it is defined in header file.
>
> On Mon, Jul 11, 2011 at 12:38 AM, nicks wrote:
>
>> Someone please help me in understanding the following output -
>>
>> Problem *1>.*
>> #include
>> #ifdef getchar //this expression is evaluated to zero.why is
>> so happening ??getchar is defined as macro in stdio.h.i mean
>> else part shouldn't be executed which is happening
>> #undef getchar
>> #else
>> #define getchar scanf("%c",&ch);
>> #endif
>> main()
>> {
>> char ch;
>>  int c;
>> c=getchar;
>> printf("%d",c);
>> }
>>
>> *OUTPUT-  1*
>> *
>> *
>> *
>> *
>> *2>.*
>> #include
>> void main()
>> {
>> long x;
>>  float t;
>> scanf("%f",&t);
>> printf("%d\n",t);
>>  x=90;
>> printf("%ld\n",x);
>> {
>>  x=1;
>> printf("%f\n",x);
>> {
>>  x=30;
>> printf("%f\n",x);
>> }
>>  printf("%f\n",x);
>> }
>> x==9;
>>  printf("%f\n",x);
>> }
>>
>> *OUTPUT(INPUT IS 2) -*
>> *2*
>> *0*
>> *90*
>> *2.00*
>> *2.00*
>> *2.00*
>> *2.00*
>> *
>> *
>> In this problem i failed to Understand why t is printed as 0 (though float
>> is converted to integer by truncation of the fractional part)
>> and how the value of t is transferred to xlooks very strange to me !!
>>
>>
>> *3>.*
>> #include
>> main()
>> {
>> printf("\nACM-CIC"+3);
>> printf(4+"\nACM-CIC");
>>
>> }
>>
>> *OUTPUT -*
>> *M-CIC-CIC*
>> *
>> *
>> What does +3 and +4 doing and does it matter to use them before the format
>> string or after it ??
>>
>> *4>.*
>> #include
>> main()
>> {
>> long long i=50;
>> i==1000;
>>  printf("i=%d\n\n%lld",sizeof(i),i);
>> //system("pause");
>> }
>>
>> *OUTPUT -*
>> *i=8*
>> *
>> *
>> *50*
>> *
>> *
>> Assigning very large value to i isn't changing it's value.why is so
>> happening ??
>>
>> and the last one
>>
>> *5>.*
>> #include
>> main()
>> {
>> static int i=0;
>>  if(i<=-1)
>> printf("\nBull's Eye");
>> else
>>  {
>> main();
>> _exit(1);
>>  }
>> i++;
>> }
>>
>> *OUTPUT -*
>> *segementation fault*
>> *
>> *
>> What's Wrong with the above Code due to which it is giving Runtime
>> errorplz help me pointing it out !!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Regards,
> Kamakshi
> kamakshi...@gmail.com
>



-- 
Regards,
Kamakshi
kamakshi...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Kamakshii Aggarwal
for the first question...it will take #ifdef getchar to be '1' only when it
is defined as a MACRO in your program..if u dont define macro it will not
take it into consideration even if it is defined in header file.

On Mon, Jul 11, 2011 at 12:38 AM, nicks  wrote:

> Someone please help me in understanding the following output -
>
> Problem *1>.*
> #include
> #ifdef getchar //this expression is evaluated to zero.why is so
> happening ??getchar is defined as macro in stdio.h.i mean else
> part shouldn't be executed which is happening
> #undef getchar
> #else
> #define getchar scanf("%c",&ch);
> #endif
> main()
> {
> char ch;
>  int c;
> c=getchar;
> printf("%d",c);
> }
>
> *OUTPUT-  1*
> *
> *
> *
> *
> *2>.*
> #include
> void main()
> {
> long x;
>  float t;
> scanf("%f",&t);
> printf("%d\n",t);
>  x=90;
> printf("%ld\n",x);
> {
>  x=1;
> printf("%f\n",x);
> {
>  x=30;
> printf("%f\n",x);
> }
>  printf("%f\n",x);
> }
> x==9;
>  printf("%f\n",x);
> }
>
> *OUTPUT(INPUT IS 2) -*
> *2*
> *0*
> *90*
> *2.00*
> *2.00*
> *2.00*
> *2.00*
> *
> *
> In this problem i failed to Understand why t is printed as 0 (though float
> is converted to integer by truncation of the fractional part)
> and how the value of t is transferred to xlooks very strange to me !!
>
>
> *3>.*
> #include
> main()
> {
> printf("\nACM-CIC"+3);
> printf(4+"\nACM-CIC");
>
> }
>
> *OUTPUT -*
> *M-CIC-CIC*
> *
> *
> What does +3 and +4 doing and does it matter to use them before the format
> string or after it ??
>
> *4>.*
> #include
> main()
> {
> long long i=50;
> i==1000;
>  printf("i=%d\n\n%lld",sizeof(i),i);
> //system("pause");
> }
>
> *OUTPUT -*
> *i=8*
> *
> *
> *50*
> *
> *
> Assigning very large value to i isn't changing it's value.why is so
> happening ??
>
> and the last one
>
> *5>.*
> #include
> main()
> {
> static int i=0;
>  if(i<=-1)
> printf("\nBull's Eye");
> else
>  {
> main();
> _exit(1);
>  }
> i++;
> }
>
> *OUTPUT -*
> *segementation fault*
> *
> *
> What's Wrong with the above Code due to which it is giving Runtime
> errorplz help me pointing it out !!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Regards,
Kamakshi
kamakshi...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Sandeep Jain
*Problem 2:*
I think u are using TurboC, since you have written void main()
Secondly, printf (since based on macros) scans through the format string.
And the it process arguments one by one depending on the format specifiers
given in this string.
I've observed that whenever there is a mismatch between the argument passed
& the format specifier, all subsequent values printed exhibit undefined
behavior.

*Problem 3:*
String literals are equivalent to char*.
Now when you write something like "hello"+1, it is treated as a
string beginning from the second character i.e. "ello"
So in your case
"\nACM-CIC"+3 ==> "M-CIC"
and 4+"\nACM-CIC" ==> "\nACM-CIC"+4 ==> "-CIC"
It has nothing to do with format string, rather char* (string literals
themselves)

*Problem 4:*
you are not assigning anything to i


Regards,
Sandeep Jain



On Mon, Jul 11, 2011 at 12:38 AM, nicks  wrote:

> Someone please help me in understanding the following output -
>
> Problem *1>.*
> #include
> #ifdef getchar //this expression is evaluated to zero.why is so
> happening ??getchar is defined as macro in stdio.h.i mean else
> part shouldn't be executed which is happening
> #undef getchar
> #else
> #define getchar scanf("%c",&ch);
> #endif
> main()
> {
> char ch;
>  int c;
> c=getchar;
> printf("%d",c);
> }
>
> *OUTPUT-  1*
> *
> *
> *
> *
> *2>.*
> #include
> void main()
> {
> long x;
>  float t;
> scanf("%f",&t);
> printf("%d\n",t);
>  x=90;
> printf("%ld\n",x);
> {
>  x=1;
> printf("%f\n",x);
> {
>  x=30;
> printf("%f\n",x);
> }
>  printf("%f\n",x);
> }
> x==9;
>  printf("%f\n",x);
> }
>
> *OUTPUT(INPUT IS 2) -*
> *2*
> *0*
> *90*
> *2.00*
> *2.00*
> *2.00*
> *2.00*
> *
> *
> In this problem i failed to Understand why t is printed as 0 (though float
> is converted to integer by truncation of the fractional part)
> and how the value of t is transferred to xlooks very strange to me !!
>
>
> *3>.*
> #include
> main()
> {
> printf("\nACM-CIC"+3);
> printf(4+"\nACM-CIC");
>
> }
>
> *OUTPUT -*
> *M-CIC-CIC*
> *
> *
> What does +3 and +4 doing and does it matter to use them before the format
> string or after it ??
>
> *4>.*
> #include
> main()
> {
> long long i=50;
> i==1000;
>  printf("i=%d\n\n%lld",sizeof(i),i);
> //system("pause");
> }
>
> *OUTPUT -*
> *i=8*
> *
> *
> *50*
> *
> *
> Assigning very large value to i isn't changing it's value.why is so
> happening ??
>
> and the last one
>
> *5>.*
> #include
> main()
> {
> static int i=0;
>  if(i<=-1)
> printf("\nBull's Eye");
> else
>  {
> main();
> _exit(1);
>  }
> i++;
> }
>
> *OUTPUT -*
> *segementation fault*
> *
> *
> What's Wrong with the above Code due to which it is giving Runtime
> errorplz help me pointing it out !!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] C OUTPUT HELP

2011-07-10 Thread nicks
Someone please help me in understanding the following output -

Problem *1>.*
#include
#ifdef getchar //this expression is evaluated to zero.why is so
happening ??getchar is defined as macro in stdio.h.i mean else
part shouldn't be executed which is happening
#undef getchar
#else
#define getchar scanf("%c",&ch);
#endif
main()
{
char ch;
int c;
c=getchar;
printf("%d",c);
}

*OUTPUT-  1*
*
*
*
*
*2>.*
#include
void main()
{
long x;
float t;
scanf("%f",&t);
printf("%d\n",t);
x=90;
printf("%ld\n",x);
{
x=1;
printf("%f\n",x);
{
x=30;
printf("%f\n",x);
}
printf("%f\n",x);
}
x==9;
printf("%f\n",x);
}

*OUTPUT(INPUT IS 2) -*
*2*
*0*
*90*
*2.00*
*2.00*
*2.00*
*2.00*
*
*
In this problem i failed to Understand why t is printed as 0 (though float
is converted to integer by truncation of the fractional part)
and how the value of t is transferred to xlooks very strange to me !!


*3>.*
#include
main()
{
printf("\nACM-CIC"+3);
printf(4+"\nACM-CIC");

}

*OUTPUT -*
*M-CIC-CIC*
*
*
What does +3 and +4 doing and does it matter to use them before the format
string or after it ??

*4>.*
#include
main()
{
long long i=50;
i==1000;
printf("i=%d\n\n%lld",sizeof(i),i);
//system("pause");
}

*OUTPUT -*
*i=8*
*
*
*50*
*
*
Assigning very large value to i isn't changing it's value.why is so
happening ??

and the last one

*5>.*
#include
main()
{
static int i=0;
if(i<=-1)
printf("\nBull's Eye");
else
{
main();
_exit(1);
}
i++;
}

*OUTPUT -*
*segementation fault*
*
*
What's Wrong with the above Code due to which it is giving Runtime
errorplz help me pointing it out !!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread varun pahwa
yes the output is compiler dependent.

On Sun, Jun 12, 2011 at 6:35 AM, nicks  wrote:

> but program by anika is giving *7 6 8* on gcc.but *7 6 6 *on
> dev-cpp...i am wondering if the output is compiler dependent !!
>
>
> On Sun, Jun 12, 2011 at 6:33 AM, nicks  wrote:
>
>> no it's
>> a=1 b=1
>> i=2
>>
>> i ran it on gcc (linux ubuntu 11.04)
>>
>>
>> On Sun, Jun 12, 2011 at 6:26 AM, sanjay ahuja > > wrote:
>>
>>> with GCC the above code gives a = 1 and b = 2
>>>
>>>
>>> On Sun, Jun 12, 2011 at 6:39 PM, nicks 
>>> wrote:
>>> > @himanshuwhat abt this ??
>>> >
>>> > #include
>>> > # include 
>>> > int i=2;
>>> > main()
>>> > {
>>> >  void add();
>>> >  add(i++,--i);
>>> > printf("\ni=%d \n",i);system("pause");
>>> > }
>>> > void add(int a ,int b)
>>> > {
>>> >  printf("\na=%d b=%d",a,b);
>>> > }
>>> >
>>> >  OUTPUT -
>>> > a=1 b=1
>>> > i=2
>>> >
>>> > acc. to ur logic output should be -
>>> > a=1 b=2
>>> > i=2
>>> >
>>> >
>>> > On Sun, Jun 12, 2011 at 5:42 AM, Anika Jain 
>>> wrote:
>>> >>
>>> >> thanks himanshu finally i got the reason!!
>>> >> :)
>>> >>
>>> >> On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal
>>> >>  wrote:
>>> >>>
>>> >>> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to
>>> a
>>> >>> pre increment expression is delayed vry mch
>>> >>> so on eval frm right to left
>>> >>> frst a is incremented...(6) bt remember d new value is nt pushed on
>>> stack
>>> >>> till nw(cz assgnmnt is delayed)
>>> >>> thn next value is 6...nd thn a is incremented.here being a post
>>> >>> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
>>> >>> incrementd to 7
>>> >>> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to
>>> 8.
>>> >>> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
>>> >>> nw).hence 3rd arg becomes 8.
>>> >>> so it prints 7 6 8..
>>> >>>
>>> >>> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain 
>>> >>> wrote:
>>> 
>>>  can anybody explain that in following code y output is coming to be:
>>> 7 6
>>>  8
>>> 
>>>  void call(int a,int b,int c)
>>>  {
>>>   printf("%d %d %d",a,b,c);
>>>  }
>>> 
>>>  int main()
>>>  {
>>>  int a=5;
>>>  call(a++,a++,++a);
>>>  return 0;
>>>  }
>>> 
>>> 
>>>  On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi
>>>   wrote:
>>> >
>>> > IN second program:
>>> >  in function value are always push in the stack from right.
>>> > so first value is --i that will make i=1 and value 1 will be passed
>>> to
>>> > function
>>> > and
>>> > after that i++ that's means i will be passed.
>>> > so 1 will be passed and after passing value. i will changed to 2.
>>> >
>>> > if u want to know why reverse order than can go through:
>>> >
>>> > http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
>>> > -
>>> > PRAMENDRA RATHI
>>> > NIT ALLAHABAD
>>> >
>>> >
>>> >
>>> >
>>> > On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki <
>>> vishaltha...@gmail.com>
>>> > wrote:
>>> >>
>>> >> In 1st program, 2nd printf requires one more argument. And
>>> basically
>>> >> %a is used for printing a double value in hex. see "man 3 printf".
>>> >>
>>> >> On Sat, Jun 11, 2011 at 5:29 PM, nicks <
>>> crazy.logic.k...@gmail.com>
>>> >> wrote:
>>> >> > Hello friends..plz help me in understanding the following C
>>> Output
>>> >> >
>>> >> > first one is --
>>> >> >
>>> >> > #include
>>> >> > #include
>>> >> > main()
>>> >> > {
>>> >> > int a=5;
>>> >> > printf("a=%d\n",a);
>>> >> > printf("%a=%d",a);
>>> >> > getch();
>>> >> > }
>>> >> > OUTPUT -
>>> >> > a=5
>>> >> > 0x1.2ff380p-1021=4199082
>>> >> >
>>> >> >
>>> >> > and the other one is --
>>> >> >
>>> >> > #include
>>> >> > # include 
>>> >> > int i=2;
>>> >> > main()
>>> >> > {
>>> >> >  void add();
>>> >> >  add(i++,--i);
>>> >> > printf("\ni=%d \n",i);system("pause");
>>> >> > }
>>> >> > void add(int a ,int b)
>>> >> > {
>>> >> >  printf("\na=%d b=%d",a,b);
>>> >> > }
>>> >> >
>>> >> >  OUTPUT -
>>> >> > a=1 b=1
>>> >> > i=2
>>> >> >
>>> >> > --
>>> >> > You received this message because you are subscribed to the
>>> Google
>>> >> > Groups
>>> >> > "Algorithm Geeks" group.
>>> >> > To post to this group, send email to algogeeks@googlegroups.com
>>> .
>>> >> > To unsubscribe from this group, send email to
>>> >> > algogeeks+unsubscr...@googlegroups.com.
>>> >> > For more options, visit this group at
>>> >> > http://groups.google.com/group/algogeeks?hl=en.
>>> >> >
>>> >>
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> >> Groups "Algorithm Geeks" group.
>>>

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread nicks
but program by anika is giving *7 6 8* on gcc.but *7 6 6 *on
dev-cpp...i am wondering if the output is compiler dependent !!

On Sun, Jun 12, 2011 at 6:33 AM, nicks  wrote:

> no it's
> a=1 b=1
> i=2
>
> i ran it on gcc (linux ubuntu 11.04)
>
>
> On Sun, Jun 12, 2011 at 6:26 AM, sanjay ahuja 
> wrote:
>
>> with GCC the above code gives a = 1 and b = 2
>>
>>
>> On Sun, Jun 12, 2011 at 6:39 PM, nicks 
>> wrote:
>> > @himanshuwhat abt this ??
>> >
>> > #include
>> > # include 
>> > int i=2;
>> > main()
>> > {
>> >  void add();
>> >  add(i++,--i);
>> > printf("\ni=%d \n",i);system("pause");
>> > }
>> > void add(int a ,int b)
>> > {
>> >  printf("\na=%d b=%d",a,b);
>> > }
>> >
>> >  OUTPUT -
>> > a=1 b=1
>> > i=2
>> >
>> > acc. to ur logic output should be -
>> > a=1 b=2
>> > i=2
>> >
>> >
>> > On Sun, Jun 12, 2011 at 5:42 AM, Anika Jain 
>> wrote:
>> >>
>> >> thanks himanshu finally i got the reason!!
>> >> :)
>> >>
>> >> On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal
>> >>  wrote:
>> >>>
>> >>> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to a
>> >>> pre increment expression is delayed vry mch
>> >>> so on eval frm right to left
>> >>> frst a is incremented...(6) bt remember d new value is nt pushed on
>> stack
>> >>> till nw(cz assgnmnt is delayed)
>> >>> thn next value is 6...nd thn a is incremented.here being a post
>> >>> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
>> >>> incrementd to 7
>> >>> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to
>> 8.
>> >>> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
>> >>> nw).hence 3rd arg becomes 8.
>> >>> so it prints 7 6 8..
>> >>>
>> >>> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain 
>> >>> wrote:
>> 
>>  can anybody explain that in following code y output is coming to be:
>> 7 6
>>  8
>> 
>>  void call(int a,int b,int c)
>>  {
>>   printf("%d %d %d",a,b,c);
>>  }
>> 
>>  int main()
>>  {
>>  int a=5;
>>  call(a++,a++,++a);
>>  return 0;
>>  }
>> 
>> 
>>  On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi
>>   wrote:
>> >
>> > IN second program:
>> >  in function value are always push in the stack from right.
>> > so first value is --i that will make i=1 and value 1 will be passed
>> to
>> > function
>> > and
>> > after that i++ that's means i will be passed.
>> > so 1 will be passed and after passing value. i will changed to 2.
>> >
>> > if u want to know why reverse order than can go through:
>> >
>> > http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
>> > -
>> > PRAMENDRA RATHI
>> > NIT ALLAHABAD
>> >
>> >
>> >
>> >
>> > On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki <
>> vishaltha...@gmail.com>
>> > wrote:
>> >>
>> >> In 1st program, 2nd printf requires one more argument. And
>> basically
>> >> %a is used for printing a double value in hex. see "man 3 printf".
>> >>
>> >> On Sat, Jun 11, 2011 at 5:29 PM, nicks > >
>> >> wrote:
>> >> > Hello friends..plz help me in understanding the following C
>> Output
>> >> >
>> >> > first one is --
>> >> >
>> >> > #include
>> >> > #include
>> >> > main()
>> >> > {
>> >> > int a=5;
>> >> > printf("a=%d\n",a);
>> >> > printf("%a=%d",a);
>> >> > getch();
>> >> > }
>> >> > OUTPUT -
>> >> > a=5
>> >> > 0x1.2ff380p-1021=4199082
>> >> >
>> >> >
>> >> > and the other one is --
>> >> >
>> >> > #include
>> >> > # include 
>> >> > int i=2;
>> >> > main()
>> >> > {
>> >> >  void add();
>> >> >  add(i++,--i);
>> >> > printf("\ni=%d \n",i);system("pause");
>> >> > }
>> >> > void add(int a ,int b)
>> >> > {
>> >> >  printf("\na=%d b=%d",a,b);
>> >> > }
>> >> >
>> >> >  OUTPUT -
>> >> > a=1 b=1
>> >> > i=2
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the
>> Google
>> >> > Groups
>> >> > "Algorithm Geeks" group.
>> >> > To post to this group, send email to algogeeks@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > algogeeks+unsubscr...@googlegroups.com.
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/algogeeks?hl=en.
>> >> >
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Algorithm Geeks" group.
>> >> To post to this group, send email to algogeeks@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> algogeeks+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> 

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread nicks
no it's
a=1 b=1
i=2

i ran it on gcc (linux ubuntu 11.04)

On Sun, Jun 12, 2011 at 6:26 AM, sanjay ahuja wrote:

> with GCC the above code gives a = 1 and b = 2
>
>
> On Sun, Jun 12, 2011 at 6:39 PM, nicks  wrote:
> > @himanshuwhat abt this ??
> >
> > #include
> > # include 
> > int i=2;
> > main()
> > {
> >  void add();
> >  add(i++,--i);
> > printf("\ni=%d \n",i);system("pause");
> > }
> > void add(int a ,int b)
> > {
> >  printf("\na=%d b=%d",a,b);
> > }
> >
> >  OUTPUT -
> > a=1 b=1
> > i=2
> >
> > acc. to ur logic output should be -
> > a=1 b=2
> > i=2
> >
> >
> > On Sun, Jun 12, 2011 at 5:42 AM, Anika Jain 
> wrote:
> >>
> >> thanks himanshu finally i got the reason!!
> >> :)
> >>
> >> On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal
> >>  wrote:
> >>>
> >>> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to a
> >>> pre increment expression is delayed vry mch
> >>> so on eval frm right to left
> >>> frst a is incremented...(6) bt remember d new value is nt pushed on
> stack
> >>> till nw(cz assgnmnt is delayed)
> >>> thn next value is 6...nd thn a is incremented.here being a post
> >>> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
> >>> incrementd to 7
> >>> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to
> 8.
> >>> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
> >>> nw).hence 3rd arg becomes 8.
> >>> so it prints 7 6 8..
> >>>
> >>> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain 
> >>> wrote:
> 
>  can anybody explain that in following code y output is coming to be: 7
> 6
>  8
> 
>  void call(int a,int b,int c)
>  {
>   printf("%d %d %d",a,b,c);
>  }
> 
>  int main()
>  {
>  int a=5;
>  call(a++,a++,++a);
>  return 0;
>  }
> 
> 
>  On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi
>   wrote:
> >
> > IN second program:
> >  in function value are always push in the stack from right.
> > so first value is --i that will make i=1 and value 1 will be passed
> to
> > function
> > and
> > after that i++ that's means i will be passed.
> > so 1 will be passed and after passing value. i will changed to 2.
> >
> > if u want to know why reverse order than can go through:
> >
> > http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
> > -
> > PRAMENDRA RATHI
> > NIT ALLAHABAD
> >
> >
> >
> >
> > On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki <
> vishaltha...@gmail.com>
> > wrote:
> >>
> >> In 1st program, 2nd printf requires one more argument. And basically
> >> %a is used for printing a double value in hex. see "man 3 printf".
> >>
> >> On Sat, Jun 11, 2011 at 5:29 PM, nicks 
> >> wrote:
> >> > Hello friends..plz help me in understanding the following C Output
> >> >
> >> > first one is --
> >> >
> >> > #include
> >> > #include
> >> > main()
> >> > {
> >> > int a=5;
> >> > printf("a=%d\n",a);
> >> > printf("%a=%d",a);
> >> > getch();
> >> > }
> >> > OUTPUT -
> >> > a=5
> >> > 0x1.2ff380p-1021=4199082
> >> >
> >> >
> >> > and the other one is --
> >> >
> >> > #include
> >> > # include 
> >> > int i=2;
> >> > main()
> >> > {
> >> >  void add();
> >> >  add(i++,--i);
> >> > printf("\ni=%d \n",i);system("pause");
> >> > }
> >> > void add(int a ,int b)
> >> > {
> >> >  printf("\na=%d b=%d",a,b);
> >> > }
> >> >
> >> >  OUTPUT -
> >> > a=1 b=1
> >> > i=2
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Algorithm Geeks" group.
> >> > To post to this group, send email to algogeeks@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > algogeeks+unsubscr...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/algogeeks?hl=en.
> >> >
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Algorithm Geeks" group.
> >> To post to this group, send email to algogeeks@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> algogeeks+unsubscr...@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread sanjay ahuja
with GCC the above code gives a = 1 and b = 2


On Sun, Jun 12, 2011 at 6:39 PM, nicks  wrote:
> @himanshuwhat abt this ??
>
> #include
> # include 
> int i=2;
> main()
> {
>  void add();
>  add(i++,--i);
>     printf("\ni=%d \n",i);system("pause");
> }
> void add(int a ,int b)
> {
>  printf("\na=%d b=%d",a,b);
> }
>
>  OUTPUT -
> a=1 b=1
> i=2
>
> acc. to ur logic output should be -
> a=1 b=2
> i=2
>
>
> On Sun, Jun 12, 2011 at 5:42 AM, Anika Jain  wrote:
>>
>> thanks himanshu finally i got the reason!!
>> :)
>>
>> On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal
>>  wrote:
>>>
>>> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to a
>>> pre increment expression is delayed vry mch
>>> so on eval frm right to left
>>> frst a is incremented...(6) bt remember d new value is nt pushed on stack
>>> till nw(cz assgnmnt is delayed)
>>> thn next value is 6...nd thn a is incremented.here being a post
>>> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
>>> incrementd to 7
>>> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to 8.
>>> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
>>> nw).hence 3rd arg becomes 8.
>>> so it prints 7 6 8..
>>>
>>> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain 
>>> wrote:

 can anybody explain that in following code y output is coming to be: 7 6
 8

 void call(int a,int b,int c)
 {
  printf("%d %d %d",a,b,c);
 }

 int main()
 {
 int a=5;
 call(a++,a++,++a);
 return 0;
 }


 On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi
  wrote:
>
> IN second program:
>  in function value are always push in the stack from right.
> so first value is --i that will make i=1 and value 1 will be passed to
> function
> and
> after that i++ that's means i will be passed.
> so 1 will be passed and after passing value. i will changed to 2.
>
> if u want to know why reverse order than can go through:
>
> http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
> -
> PRAMENDRA RATHI
> NIT ALLAHABAD
>
>
>
>
> On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki 
> wrote:
>>
>> In 1st program, 2nd printf requires one more argument. And basically
>> %a is used for printing a double value in hex. see "man 3 printf".
>>
>> On Sat, Jun 11, 2011 at 5:29 PM, nicks 
>> wrote:
>> > Hello friends..plz help me in understanding the following C Output
>> >
>> > first one is --
>> >
>> > #include
>> > #include
>> > main()
>> > {
>> > int a=5;
>> > printf("a=%d\n",a);
>> > printf("%a=%d",a);
>> > getch();
>> > }
>> > OUTPUT -
>> > a=5
>> > 0x1.2ff380p-1021=4199082
>> >
>> >
>> > and the other one is --
>> >
>> > #include
>> > # include 
>> > int i=2;
>> > main()
>> > {
>> >  void add();
>> >  add(i++,--i);
>> >     printf("\ni=%d \n",i);system("pause");
>> > }
>> > void add(int a ,int b)
>> > {
>> >  printf("\na=%d b=%d",a,b);
>> > }
>> >
>> >  OUTPUT -
>> > a=1 b=1
>> > i=2
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>>
>>> --
>>>
>>>   Regards
>>> Himanshu Kansal
>>>   Msc Comp.

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread nicks
@umesh...thanks :) this explanation seems to be satisfactory but failed to
understand from where @anika and @himanshu were getting 7 6 8i ran
it...output comes out to be 7 6 6  !!

On Sun, Jun 12, 2011 at 6:15 AM, UMESH KUMAR wrote:

>
 void call(int a,int b,int c)
 {
  printf("%d %d %d",a,b,c);
 }

 int main()
 {
 int a=5;
 call(a++,a++,++a);
 return 0;

 }


 On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi <
 prathi...@gmail.com> wrote:

> IN second program:
>  in function value are always push in the stack from right.
> so first value is --i that will make i=1 and value 1 will be passed to
> function
> and
> after that i++ that's means i will be passed.
> so 1 will be passed and after passing value. i will changed to 2.
>
> if u want to know why reverse order than can go through:
> http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
> -
> PRAMENDRA RATHI
> NIT ALLAHABAD
>
>
>
> When the function is called then formal values PUSH in a
>

>  STACK from left to right and  POP from left to right finally
> so we can obtained the output :7 6 6 ...
>
>  Since function call --
>
> * call(a++,a++,++a);*
> * and *a=5
>
>STACK PUSH AS:-
> 0::++a c
> 1::a++ b
> 2::a++ a
>
>   POP AS:
>
>0::++a c=   6 ( *6)*
> *
> *
> *  *1::a++ b =  6  (*7*)
>
>   2::a++ a =  7  (*8*)
>
>  So. finally OUTPUT :-
> * a=7, b=6, c=6*
> *
> *
> *
> *
> **
> *
> *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread UMESH KUMAR
>
>
>>> void call(int a,int b,int c)
>>> {
>>>  printf("%d %d %d",a,b,c);
>>> }
>>>
>>> int main()
>>> {
>>> int a=5;
>>> call(a++,a++,++a);
>>> return 0;
>>>
>>> }
>>>
>>>
>>> On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi <
>>> prathi...@gmail.com> wrote:
>>>
 IN second program:
  in function value are always push in the stack from right.
 so first value is --i that will make i=1 and value 1 will be passed to
 function
 and
 after that i++ that's means i will be passed.
 so 1 will be passed and after passing value. i will changed to 2.

 if u want to know why reverse order than can go through:
 http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
 -
 PRAMENDRA RATHI
 NIT ALLAHABAD



 When the function is called then formal values PUSH in a

>>>
 STACK from left to right and  POP from left to right finally
so we can obtained the output :7 6 6 ...

 Since function call --

* call(a++,a++,++a);*
* and *a=5

   STACK PUSH AS:-
0::++a c
1::a++ b
2::a++ a

  POP AS:

   0::++a c=   6 ( *6)*
*
*
*  *1::a++ b =  6  (*7*)

  2::a++ a =  7  (*8*)

 So. finally OUTPUT :-
* a=7, b=6, c=6*
*
*
*
*
**
*
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread nicks
@himanshuwhat abt this ??

#include
# include 
int i=2;
main()
{
 void add();
 add(i++,--i);
printf("\ni=%d \n",i);system("pause");
}
void add(int a ,int b)
{
 printf("\na=%d b=%d",a,b);
}

 *OUTPUT -*
a=1 b=1
i=2

acc. to ur logic output should be -
a=1 b=2
i=2


On Sun, Jun 12, 2011 at 5:42 AM, Anika Jain  wrote:

> thanks himanshu finally i got the reason!!
> :)
>
>
> On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal <
> himanshukansal...@gmail.com> wrote:
>
>> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to a pre
>> increment expression is delayed vry mch
>> so on eval frm right to left
>> frst a is incremented...(6) bt remember d new value is nt pushed on stack
>> till nw(cz assgnmnt is delayed)
>> thn next value is 6...nd thn a is incremented.here being a post
>> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
>> incrementd to 7
>> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to 8.
>> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
>> nw).hence 3rd arg becomes 8.
>> so it prints 7 6 8..
>>
>> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain wrote:
>>
>>> can anybody explain that in following code y output is coming to be: 7 6
>>> 8
>>>
>>> void call(int a,int b,int c)
>>> {
>>>  printf("%d %d %d",a,b,c);
>>> }
>>>
>>> int main()
>>> {
>>> int a=5;
>>> call(a++,a++,++a);
>>> return 0;
>>>
>>> }
>>>
>>>
>>> On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi <
>>> prathi...@gmail.com> wrote:
>>>
 IN second program:
  in function value are always push in the stack from right.
 so first value is --i that will make i=1 and value 1 will be passed to
 function
 and
 after that i++ that's means i will be passed.
 so 1 will be passed and after passing value. i will changed to 2.

 if u want to know why reverse order than can go through:
 http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
 -
 PRAMENDRA RATHI
 NIT ALLAHABAD




 On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki 
 wrote:

> In 1st program, 2nd printf requires one more argument. And basically
> %a is used for printing a double value in hex. see "man 3 printf".
>
> On Sat, Jun 11, 2011 at 5:29 PM, nicks 
> wrote:
> > Hello friends..plz help me in understanding the following C Output
> >
> > first one is --
> >
> > #include
> > #include
> > main()
> > {
> > int a=5;
> > printf("a=%d\n",a);
> > printf("%a=%d",a);
> > getch();
> > }
> > OUTPUT -
> > a=5
> > 0x1.2ff380p-1021=4199082
> >
> >
> > and the other one is --
> >
> > #include
> > # include 
> > int i=2;
> > main()
> > {
> >  void add();
> >  add(i++,--i);
> > printf("\ni=%d \n",i);system("pause");
> > }
> > void add(int a ,int b)
> > {
> >  printf("\na=%d b=%d",a,b);
> > }
> >
> >  OUTPUT -
> > a=1 b=1
> > i=2
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
  --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>>
>>   Regards
>> Himanshu Kansal
>>   Msc Comp. sc.
>> (University of Delhi)
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread Anika Jain
thanks himanshu finally i got the reason!!
:)

On Sun, Jun 12, 2011 at 5:59 PM, himanshu kansal <
himanshukansal...@gmail.com> wrote:

> @anika:cz on gcc arguemnts r eval frm right to left and assgnment to a pre
> increment expression is delayed vry mch
> so on eval frm right to left
> frst a is incremented...(6) bt remember d new value is nt pushed on stack
> till nw(cz assgnmnt is delayed)
> thn next value is 6...nd thn a is incremented.here being a post
> increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
> incrementd to 7
> simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to 8.
> nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
> nw).hence 3rd arg becomes 8.
> so it prints 7 6 8..
>
> On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain wrote:
>
>> can anybody explain that in following code y output is coming to be: 7 6 8
>>
>> void call(int a,int b,int c)
>> {
>>  printf("%d %d %d",a,b,c);
>> }
>>
>> int main()
>> {
>> int a=5;
>> call(a++,a++,++a);
>> return 0;
>>
>> }
>>
>>
>> On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi <
>> prathi...@gmail.com> wrote:
>>
>>> IN second program:
>>>  in function value are always push in the stack from right.
>>> so first value is --i that will make i=1 and value 1 will be passed to
>>> function
>>> and
>>> after that i++ that's means i will be passed.
>>> so 1 will be passed and after passing value. i will changed to 2.
>>>
>>> if u want to know why reverse order than can go through:
>>> http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
>>> -
>>> PRAMENDRA RATHI
>>> NIT ALLAHABAD
>>>
>>>
>>>
>>>
>>> On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki 
>>> wrote:
>>>
 In 1st program, 2nd printf requires one more argument. And basically
 %a is used for printing a double value in hex. see "man 3 printf".

 On Sat, Jun 11, 2011 at 5:29 PM, nicks 
 wrote:
 > Hello friends..plz help me in understanding the following C Output
 >
 > first one is --
 >
 > #include
 > #include
 > main()
 > {
 > int a=5;
 > printf("a=%d\n",a);
 > printf("%a=%d",a);
 > getch();
 > }
 > OUTPUT -
 > a=5
 > 0x1.2ff380p-1021=4199082
 >
 >
 > and the other one is --
 >
 > #include
 > # include 
 > int i=2;
 > main()
 > {
 >  void add();
 >  add(i++,--i);
 > printf("\ni=%d \n",i);system("pause");
 > }
 > void add(int a ,int b)
 > {
 >  printf("\na=%d b=%d",a,b);
 > }
 >
 >  OUTPUT -
 > a=1 b=1
 > i=2
 >
 > --
 > You received this message because you are subscribed to the Google
 Groups
 > "Algorithm Geeks" group.
 > To post to this group, send email to algogeeks@googlegroups.com.
 > To unsubscribe from this group, send email to
 > algogeeks+unsubscr...@googlegroups.com.
 > For more options, visit this group at
 > http://groups.google.com/group/algogeeks?hl=en.
 >

 --
 You received this message because you are subscribed to the Google
 Groups "Algorithm Geeks" group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
>
>   Regards
> Himanshu Kansal
>   Msc Comp. sc.
> (University of Delhi)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@goog

Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread himanshu kansal
@anika:cz on gcc arguemnts r eval frm right to left and assgnment to a pre
increment expression is delayed vry mch
so on eval frm right to left
frst a is incremented...(6) bt remember d new value is nt pushed on stack
till nw(cz assgnmnt is delayed)
thn next value is 6...nd thn a is incremented.here being a post
increment opassgnmnt is made 1st (2nd arg to fun is 6)and a is
incrementd to 7
simalrly.assgnmnt is made(1st arg is 7) and a is incremnted to 8.
nw d assgnmnt is made to the 3rd arg(d assgnmnt whch ws delayed till
nw).hence 3rd arg becomes 8.
so it prints 7 6 8..

On Sun, Jun 12, 2011 at 5:33 PM, Anika Jain  wrote:

> can anybody explain that in following code y output is coming to be: 7 6 8
>
> void call(int a,int b,int c)
> {
>  printf("%d %d %d",a,b,c);
> }
>
> int main()
> {
> int a=5;
> call(a++,a++,++a);
> return 0;
>
> }
>
>
> On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi <
> prathi...@gmail.com> wrote:
>
>> IN second program:
>>  in function value are always push in the stack from right.
>> so first value is --i that will make i=1 and value 1 will be passed to
>> function
>> and
>> after that i++ that's means i will be passed.
>> so 1 will be passed and after passing value. i will changed to 2.
>>
>> if u want to know why reverse order than can go through:
>> http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
>> -
>> PRAMENDRA RATHI
>> NIT ALLAHABAD
>>
>>
>>
>>
>> On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki wrote:
>>
>>> In 1st program, 2nd printf requires one more argument. And basically
>>> %a is used for printing a double value in hex. see "man 3 printf".
>>>
>>> On Sat, Jun 11, 2011 at 5:29 PM, nicks 
>>> wrote:
>>> > Hello friends..plz help me in understanding the following C Output
>>> >
>>> > first one is --
>>> >
>>> > #include
>>> > #include
>>> > main()
>>> > {
>>> > int a=5;
>>> > printf("a=%d\n",a);
>>> > printf("%a=%d",a);
>>> > getch();
>>> > }
>>> > OUTPUT -
>>> > a=5
>>> > 0x1.2ff380p-1021=4199082
>>> >
>>> >
>>> > and the other one is --
>>> >
>>> > #include
>>> > # include 
>>> > int i=2;
>>> > main()
>>> > {
>>> >  void add();
>>> >  add(i++,--i);
>>> > printf("\ni=%d \n",i);system("pause");
>>> > }
>>> > void add(int a ,int b)
>>> > {
>>> >  printf("\na=%d b=%d",a,b);
>>> > }
>>> >
>>> >  OUTPUT -
>>> > a=1 b=1
>>> > i=2
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > algogeeks+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/algogeeks?hl=en.
>>> >
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 

  Regards
Himanshu Kansal
  Msc Comp. sc.
(University of Delhi)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-12 Thread Anika Jain
can anybody explain that in following code y output is coming to be: 7 6 8

void call(int a,int b,int c)
{
 printf("%d %d %d",a,b,c);
}

int main()
{
int a=5;
call(a++,a++,++a);
return 0;
}


On Sat, Jun 11, 2011 at 8:21 PM, PRAMENDRA RATHi rathi
wrote:

> IN second program:
>  in function value are always push in the stack from right.
> so first value is --i that will make i=1 and value 1 will be passed to
> function
> and
> after that i++ that's means i will be passed.
> so 1 will be passed and after passing value. i will changed to 2.
>
> if u want to know why reverse order than can go through:
> http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
> -
> PRAMENDRA RATHI
> NIT ALLAHABAD
>
>
>
>
> On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki wrote:
>
>> In 1st program, 2nd printf requires one more argument. And basically
>> %a is used for printing a double value in hex. see "man 3 printf".
>>
>> On Sat, Jun 11, 2011 at 5:29 PM, nicks 
>> wrote:
>> > Hello friends..plz help me in understanding the following C Output
>> >
>> > first one is --
>> >
>> > #include
>> > #include
>> > main()
>> > {
>> > int a=5;
>> > printf("a=%d\n",a);
>> > printf("%a=%d",a);
>> > getch();
>> > }
>> > OUTPUT -
>> > a=5
>> > 0x1.2ff380p-1021=4199082
>> >
>> >
>> > and the other one is --
>> >
>> > #include
>> > # include 
>> > int i=2;
>> > main()
>> > {
>> >  void add();
>> >  add(i++,--i);
>> > printf("\ni=%d \n",i);system("pause");
>> > }
>> > void add(int a ,int b)
>> > {
>> >  printf("\na=%d b=%d",a,b);
>> > }
>> >
>> >  OUTPUT -
>> > a=1 b=1
>> > i=2
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Algorithm Geeks" group.
>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > algogeeks+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-11 Thread PRAMENDRA RATHi rathi
IN second program:
 in function value are always push in the stack from right.
so first value is --i that will make i=1 and value 1 will be passed to
function
and
after that i++ that's means i will be passed.
so 1 will be passed and after passing value. i will changed to 2.

if u want to know why reverse order than can go through:
http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
-
PRAMENDRA RATHI
NIT ALLAHABAD




On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki wrote:

> In 1st program, 2nd printf requires one more argument. And basically
> %a is used for printing a double value in hex. see "man 3 printf".
>
> On Sat, Jun 11, 2011 at 5:29 PM, nicks  wrote:
> > Hello friends..plz help me in understanding the following C Output
> >
> > first one is --
> >
> > #include
> > #include
> > main()
> > {
> > int a=5;
> > printf("a=%d\n",a);
> > printf("%a=%d",a);
> > getch();
> > }
> > OUTPUT -
> > a=5
> > 0x1.2ff380p-1021=4199082
> >
> >
> > and the other one is --
> >
> > #include
> > # include 
> > int i=2;
> > main()
> > {
> >  void add();
> >  add(i++,--i);
> > printf("\ni=%d \n",i);system("pause");
> > }
> > void add(int a ,int b)
> > {
> >  printf("\na=%d b=%d",a,b);
> > }
> >
> >  OUTPUT -
> > a=1 b=1
> > i=2
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-11 Thread PRAMENDRA RATHi rathi
IN second program:
 in function value are always push in the stack from left.
so first value is --i that will make i=1 and pass to function
and
after that i++ will be passed.that's means i will be passed and after that
value will be incremented.
so 1 will pass and after passing value. i will changed to 2.


if u wnat to know why reverse order than can go through:

http://cs.nyu.edu/courses/fall03/V22.0201-003/c_param.html
-
PRAMENDRA RATHI
NIT ALLAHABAD




On Sat, Jun 11, 2011 at 7:28 PM, Vishal Thanki wrote:

> In 1st program, 2nd printf requires one more argument. And basically
> %a is used for printing a double value in hex. see "man 3 printf".
>
> On Sat, Jun 11, 2011 at 5:29 PM, nicks  wrote:
> > Hello friends..plz help me in understanding the following C Output
> >
> > first one is --
> >
> > #include
> > #include
> > main()
> > {
> > int a=5;
> > printf("a=%d\n",a);
> > printf("%a=%d",a);
> > getch();
> > }
> > OUTPUT -
> > a=5
> > 0x1.2ff380p-1021=4199082
> >
> >
> > and the other one is --
> >
> > #include
> > # include 
> > int i=2;
> > main()
> > {
> >  void add();
> >  add(i++,--i);
> > printf("\ni=%d \n",i);system("pause");
> > }
> > void add(int a ,int b)
> > {
> >  printf("\na=%d b=%d",a,b);
> > }
> >
> >  OUTPUT -
> > a=1 b=1
> > i=2
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT HELP

2011-06-11 Thread Vishal Thanki
In 1st program, 2nd printf requires one more argument. And basically
%a is used for printing a double value in hex. see "man 3 printf".

On Sat, Jun 11, 2011 at 5:29 PM, nicks  wrote:
> Hello friends..plz help me in understanding the following C Output
>
> first one is --
>
> #include
> #include
> main()
> {
> int a=5;
> printf("a=%d\n",a);
> printf("%a=%d",a);
> getch();
> }
> OUTPUT -
> a=5
> 0x1.2ff380p-1021=4199082
>
>
> and the other one is --
>
> #include
> # include 
> int i=2;
> main()
> {
>  void add();
>  add(i++,--i);
>     printf("\ni=%d \n",i);system("pause");
> }
> void add(int a ,int b)
> {
>  printf("\na=%d b=%d",a,b);
> }
>
>  OUTPUT -
> a=1 b=1
> i=2
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] C OUTPUT HELP

2011-06-11 Thread nicks
Hello friends..plz help me in understanding the following C Output

first one is --

#include
#include
main()
{
int a=5;
printf("a=%d\n",a);
printf("%a=%d",a);
getch();
}
*OUTPUT - *
a=5
0x1.2ff380p-1021=4199082


and the other one is --

#include
# include 
int i=2;
main()
{
 void add();
 add(i++,--i);
printf("\ni=%d \n",i);system("pause");
}
void add(int a ,int b)
{
 printf("\na=%d b=%d",a,b);
}

 *OUTPUT -*
a=1 b=1
i=2

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.