C Programming - Bitwise Operators - Discussion
Discussion Forum : Bitwise Operators - Point Out Correct Statements (Q.No. 3)
3.
Which of the following statements are correct about the program?
#include<stdio.h>
char *fun(unsigned int num, int base);
int main()
{
char *s;
s=fun(128, 2);
s=fun(128, 16);
printf("%s\n",s);
return 0;
}
char *fun(unsigned int num, int base)
{
static char buff[33];
char *ptr = &buff[sizeof(buff)-1];
*ptr = '\0';
do
{
*--ptr = "0123456789abcdef"[num %base];
num /=base;
}while(num!=0);
return ptr;
}
Discussion:
19 comments Page 2 of 2.
Chandu said:
9 years ago
I don't understand this problem please explain clearly.
Kalyan said:
8 years ago
I am not getting this, Can anyone explain it clearly?
Uma said:
1 decade ago
Please give breaf explanation about this program.
Emanuel said:
9 years ago
I don't think that it is possible to use "12345".
Manjushree said:
4 years ago
Give an explanation for the given program.
Dinesh said:
1 decade ago
Why we need char to be defined as static?
Hey said:
1 decade ago
What does "0123456789abcdef" do here?
Ketan said:
1 decade ago
Why specific size 33 of buffer?
Cloud said:
1 decade ago
Why we use 0123456789abcdef?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers