STD Main ( (I I - ) (Cout ) ) : Using Namespace Int Int in For Int in

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

#include <iostream>

using namespace std;

int main() {

int in = 5;

for(int i = 0; i <= --in; ){


cout << "Go" << " ";
}

return 0;
}
Output : Go Go Go Go Go

REASON : note that here “i” is always 0 but “in” is varying

Since variable “i” is defined globally, it is initialized with default value 0. 
Switch statements doesn’t work for floating-point values.

#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("Geeks");
break;
case '1': printf("Quiz");
break;
default: printf("GeeksQuiz");
}
return 0;
}
Output : GeeksQuiz

REASON : But, the cases are labeled with characters which get converted to their ASCII
values 48(for 0) and 49(for 1). None of the cases is labeled with value 0

int i;

i = 1, 2, 3;
printf("%d", i);

Comma acts as an operator. The assignment operator has higher precedence than the
comma operator. So, the expression is considered as (i = 1), 2, 3 and 1 gets assigned to the
variable i.
In C, functions can return any type except only :arrays and functions. We can get around this
limitation by returning pointer to array or pointer to function.

You might also like