This is the C++
code:
#include<iostream>
using namespace std;
int a=8;
int fun(int &a)
{
a=a*a;
return a;
}
int main()
{
cout << a << endl \
<< fun(a) << endl \
<< a << endl;
return 0;
}
why does it output:
64 64 8
the <<
operator's associativity is left to right, so why not output 8 64 64
?
Does it have the relation to the sequence point and the effect side?
Output is dependent on the compiler. For 32 bit compiler it would be fffffffe and for 16 bit it would be fffe.
Most likely the '?' is the ternary operator. Its grammar is: RESULT = (COND) ? ( STATEMEN IF TRUE) : (STATEMENT IF FALSE) It is a nice shorthand for the typical if-else statement: if (COND) { RESULT = (STATEMENT IF TRUE); } else { RESULT = (STATEMENT IF FALSE);
In every C program, three basic functions take place – accepting of data as input, the processing of data, and the generation of output. The acceptance of data refers to input and the presentation of data refers to the output. The C program accepts input from the keyboard and displays output on the screen.
%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.
C programming provides a set of built-in functions to read the given input and feed it to the program as per requirement. When we say Output, it means to display some data on screen, printer, or in any file. C programming provides a set of built-in functions to output the data on the computer screen as well as to save it in text or binary files.
All valid C program must contain the main() function. The code execution begins from the start of main() function. The printf() is a library function to send formatted output to the screen. The printf() function is declared in "stdio.h" header file.
All valid C programs must contain the main () function. The code execution begins from the start of the main () function. The printf () is a library function to send formatted output to the screen. The function prints the string inside quotations.
The int puts (const char *s) function writes the string 's' and 'a' trailing newline to stdout. NOTE: Though it has been deprecated to use gets () function, Instead of using gets, you want to use fgets ().
Associativity and evaluation order are not the same thing. The expression a << b << c
is equivalent to (a << b) << c
due to left-to-right associativity, but when it comes to evaluation order, the compiler is free to evaluate c
first then a << b
and, likewise, it can evaluate b
before it evaluates a
. In fact, it can even evaluate the terms in the order b
→ c
→ a
if it wants, and it just might if it concludes that such an order will maximise performance by minimising pipeline stalls, cache misses, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With