Hi Praveen, 

I suggest you join "Progav" at 

http://groups.google.com/group/progav?lnk=li

However, please read till bottom

Regards
AK

--- praveen kumar <[EMAIL PROTECTED]> wrote:

> why the output of this program is 256
>    
>   main()
>   {
>   unsigned char i=0x80;
>   printf("\n%d",i<,1);
>   }

This program didn't compile. It is the problem with
the printf statement. My compiler tells me that there
is a syntax error befor ','. On removeing the ',', I
got the output 0 and then, removing the '<' gave me
the output as 128. Well, that means 0x80 is 128 in
decimal form. In your printf statement you are
printing the value of i in integer form, which is 128.

>    
>    
>   plz anyone explain the logic of the following
> programs
>    
>   main()
>   {
>   char *s;
>   s=fun(128,2);
>   printf("\n%s",s);
>   }
>   fun(unsigned int num,intbase)
>   {
>   static char buff[33];
>   char *ptr;
>   ptr=&buff[sizeof(buff)-1];

>   *ptr='\0';
    Here, you are setting the last element of the
string as '\0'. which is conventional as all strings
must end by '\0'. 
>   do
>   {
>   *--ptr="0123456789abcdef"[num%base];
>   num/=base;
>   }while(num!=0);
>   return ptr;
>   }
>    
This program is not as difficult as it looks. In
simple terms, you are creating an array buff with
selected elemets from the string '01..." and returning
the string to main(). You pass 2 numbers 128 and 2 to
your funcion fun() received by formal parameters num
and base respectively. You use a pointer ptr to handle
the string buff. The next steps in the function enter
data into the string, but in your case, it is in the
reverse order. Look in your program now.      
    
>    
>   main()
>   {
>   unsigned int num;
>   int i;
>   scanf("%u",&num);
>   for(i=0;i<16;i++)
>   printf("%d",(num<<i & 1<<15)?1:0);
>   }
> 
> 
>  
> 
>                               
> ---------------------------------
>  Jiyo cricket on Yahoo! India cricket
> Yahoo! Messenger Mobile Stay in touch with your
> buddies all the time.
> 
> [Non-text portions of this message have been
> removed]
> 
> 
> 
> >-----------------------------------------~-~>
> CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is
> available at 
> http://www.eScribe.com/software/C-Paradise/
> 
> >------------------------------------------_->
> 
> 
>  
> Yahoo! Groups Links
> 
> 
>     [EMAIL PROTECTED]
> 
>  
> 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at 
http://www.eScribe.com/software/C-Paradise/

>------------------------------------------_->


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/C-Paradise/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to