You need to read a floating-point value from the user in the C programming language. Which of the following statements correctly performs this task?
float x; scanf("%f", &x);
The C library function scanf() reads formatted input from the keyboard and stores each value at a memory location. Two things must be correct for it to work: the format specifier must match the variable's data type, and scanf must be given the address (a pointer) of the variable, not the variable's value, because scanf writes the input into that memory location.
The correct statement is:
float in scanf.x, so scanf knows where to store the value it reads.Why the other statements fail:
&x tells scanf to interpret the input as an integer and write an integer-sized bit pattern into a float variable, giving a wrong/garbage result.x as if it were a pointer, but x is a plain float, not a pointer — this is a type error and leads to undefined behaviour.& hands scanf the current (uninitialised) value of x instead of its address, so scanf tries to store data at an invalid location — again undefined behaviour, often a crash.Consider the following code snippet in C programming language.
int n = 5;
int m = n++;
What is the value of m after execution?
What is the output of the give C language code snippet?
void f(int x)
{
x = x + 5;
}
int main()
{
int a = 10;
f(a);
printf("%d",a);
return 0;
}
What are the statements that begin with # symbol called in C programming language?
Which statement is TRUE about if statement in the C programming language?
Which shape is used to represent a decision in a flowchart?
In object-oriented programming, which keyword ensures that a member variable belongs to the class itself rather than to any specific object, thereby allowing all instances to share a single copy of that variable?
The three basic structure types used to write the algorithm for a program are sequence, selection and repetition. Which of the following is NOT an advantage of using only these structures when writing the algorithm for a program?
Which statement(s) is/are true about formation of identifier in C?
I. It consist of alphabets, digits and underscore.
II. An identifier can start with an underscore.
What is the output of the code written in C?
void main()
{
printf("%d",7%-3);
printf("%d",-7%3);
}
Which of the following statement(s) is/are true about pre-processor in C/C++?
I. To replace each #include directive with the contents of the designated file.
II. To replace each escape sequence with designated character.
III. To process macro definitions and expand macro calls.