-
-
-
Point out the error in the following program main() { const int x; x=128; printf("%d",x); }
x should have been initialized where it is declared.
-
Point out the error in the following program main() { int a=10; void f(); a=f(); printf("n%d",a); } void f() { printf("nHi"); }
The program is trying to collect the value of a "void" function into an integer variable.
-
-
else
printf("I hate U");
}
">Iii) main(){ float me = 1.1; double you = 1.1; if(me==you)printf("I love U");else printf("I hate U");}
I hate UExplanation:For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with...
-
-
-
> (i - (i -1)));
}
}
">Main(){ signed int bit=512, i=5; for(;i;i--) { printf("%dn", bit >> (i - (i -1))); }}
A) 512, 512, 512, 512, 512B) 256, 256, 0, 0, 0C) 512, 256, 0, 0, 0D) 256, 256, 256, 256, 256Explanation: bit's value is not changed
-
-
-
-
-
-
-
C Code to print number in reverse
Write a program to print the given number in reverse order for e.g 123 as 321
-
Global variables in c program
If i initialize a global array locally in main function i can still access those elements in other functions as if the elements of array were global whereas this is not the case if i do the same with other basic variables like int i.can someone explain?
-
Calculate the weighted average of a list of n numbers
Calculate the weighted average of a list of n numbers using the formula
xavg = f1x1+f2x2+ ….+ fnxn
where the f’s are fractional weighting factors, i.e.,
0 -
When should the volatile modifier be used?
The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the volatile modifier is desirable. The first case involves memory-mapped hardware (a device such as a graphics adaptor that appears to the computer’s hardware as if it were part of the computer’s memory), and...
-
How can you restore a redirected standard stream?
The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using the standard C library functions named dup() and fdopen(), you can restore a standard stream such as stdout to its original state. The dup() function duplicates a file handle. You can use the dup()...
C Interview Questions
Ans