logo codesdope

why the following program gets compiled

   amankh_99

#include <iostream>
int main()
{
	int a = 42, b = 5, c;
	c = a + b;
	std :: cout < "sum = " < c;
	return 0;
}

This program does not show the desired output but it gets compiled without giving any error


Answers

  •    Amit Kumar , I.I.T. Patna

    You are using but << is the output operator, so you must use <<.

    std :: cout < "sum = "

    Here, both “sum” and cout are derived from std (wait till strings chapter if you are not familiar with strings). So, the statement above is comparing both of them and there is nothing wrong in that and that is why this code gets compiled.



Share what you know
Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.