Sail E0 Webinar
Question


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;
}
Options:
A .  It converts a number to a given base.
B .  It converts a number to its equivalent binary.
C .  It converts a number to its equivalent hexadecimal.
D .  It converts a number to its equivalent octal.
Answer: Option A



Submit Your Solution Below and Earn Points !
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers