a) Positive value
b) Zero
c) Negative value
d) None of these
Showing posts with label printf. Show all posts
Showing posts with label printf. Show all posts
Monday, February 8, 2010
Thursday, April 9, 2009
How can %f work for type double in printf and %lf is required in scanf?
Answer: In variable-length argument lists such as printf's, the old "default argument promotions" apply, and type float is implicitly converted to double. So printf always receives doubles, and defines %f to be the sequence that works whether you had passed a float or a double.
(Strictly speaking, %lf is *not* a valid printf format specifier, although most versions of printf quietly excepts it.)
scanf, on the other hand, always accepts pointers, and the types pointer-to-float and pointer-to-double are very different (especially when you're using them for storing values). No implicit promotions apply.
(Strictly speaking, %lf is *not* a valid printf format specifier, although most versions of printf quietly excepts it.)
scanf, on the other hand, always accepts pointers, and the types pointer-to-float and pointer-to-double are very different (especially when you're using them for storing values). No implicit promotions apply.
Why doesn't \% print a literal % with printf?
Answer: Backslash sequences are interpreted by the compiler (\n, \", \0, etc.), and \% is not one of the recognized backslash sequences. It's not clear what the compiler would do with a \% sequence -- it might delete it, or replace it with a single %, or perhaps pass it through as \ %. But it's printf's behavior we're trying to change, and printf's special character is %. So it's a %-sequence we should be looking for to print a literal %, and printf defines the one we want as %%.
Friday, December 26, 2008
What is the output of following programme ?
main()
{
char x = 0x8A;
unsigned int y = x;
printf("%d\n", y);
}
A. -118
B. 138
C. 118
D. Unpredictable
{
char x = 0x8A;
unsigned int y = x;
printf("%d\n", y);
}
A. -118
B. 138
C. 118
D. Unpredictable
Wednesday, December 17, 2008
Which of the following is the correct output for the program given below?
main() {
char ch;
if((ch=printf(248)))
printf("You are Boss");
else
printf("I am Boss");
}
a. You are Boss
b. I am Boss
c. No output
d. None of these
char ch;
if((ch=printf(248)))
printf("You are Boss");
else
printf("I am Boss");
}
a. You are Boss
b. I am Boss
c. No output
d. None of these
Saturday, December 6, 2008
Find the output of following programme
#include
#include
int main()
{
printf("%c\n", 'mujhe khoon do main tumhe pani duungah' -3);
return 0;
}
a. warning,Outputs: -h
b. error
c. warning, Outputs: e
d. warning, Outputs: n
e. warning, Outputs: (ascii value of h)
#include
int main()
{
printf("%c\n", 'mujhe khoon do main tumhe pani duungah' -3);
return 0;
}
a. warning,Outputs: -h
b. error
c. warning, Outputs: e
d. warning, Outputs: n
e. warning, Outputs: (ascii value of h)
Sunday, September 14, 2008
"My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above.
Choice a: printf("\"My salary was increased by 15/%\!\"\n");
Choice b: printf("My salary was increased by 15%!\n");
Choice c: printf("My salary was increased by 15'%'!\n");
Choice d: printf("\"My salary was increased by 15%%!\"\n");
Choice e: printf("\"My salary was increased by 15'%'!\"\n");
Choice a: printf("\"My salary was increased by 15/%\!\"\n");
Choice b: printf("My salary was increased by 15%!\n");
Choice c: printf("My salary was increased by 15'%'!\n");
Choice d: printf("\"My salary was increased by 15%%!\"\n");
Choice e: printf("\"My salary was increased by 15'%'!\"\n");
Subscribe to:
Posts (Atom)