[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Declarations and Initializations - Discussion

Home > C Programming > Declarations and Initializations > MCQs Questions Discussion

46 / 54

What is the output of the following 'C' program ?

#include<stdio.h>
printd (int n)
{
if (n < 0)
{
printf ("-");
n = -n;
}
if (n % 10)
printf ("%d", n);
else
printf ("%d", n/10);
printf ("%d", n);
}

If initially n = -24;

A-24

B24

C-2424

DNone of the above

Answer: Option (Login/Signup)

Show Explanation

Initially, n=24

Line 3 =>    if(n<0), is true because -24<0.

Line 5 =>    "-" get printed.

Line 6 =>    n=-n, or n=-(-24), or n=24

Line 8 =>    if(n%10), or if(24%10), or if(4), which is true as "4 is not equal to 0" is true.

Line 9 =>    "24" gets printed

Here, the else block won't get executed as if block has already executed.

Finally, Line 12 =>    "24" gets printed.

Hence, the complete output is -2424

Asked In ::

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here