answersLogoWhite

0


Best Answer

Yes, but 'cout' is not a statement! Examples for statements: null-statement, block, expression, if-else, while, do-while, for, continue, switch, break, return.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you use conditional operator in cout statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a conditional operator replace an if statement always?

No. An if statement does not require an elseclause and the expression(s) do not return anything to the caller, whereas the conditional operator always executes one of two expressions and always returns the value of the executed expression back to the caller. The executed expression may be yet another conditional operator, thus allowing simulation of nested ifs and if...else if... else statements.Consider the following example:int x = rand();if( x > 100 ) x = 100;We can achieve the same result with a conditional operator:int y = rand();y = y>100 ? 100 : y;However, if we were to expand this statement to an if statement we would not get the original if statement shown above:int z = rand();if( z > 100 ) z = 100;else z = z;The else clause is clearly unnecessary in this case, so the original if statement would be the statement of choice here.As a general rule, if you can make use of the return value in a conditional operator, and must return one of at least two values, then use the conditional operator. Otherwise use an if statement.


How do you use the conditional statement of turbo c?

#include<stdio.h> void main() { int a=10,b=15; clrscr(); if(a>b) printf("%d is the large number",a); else printf("%d is the large number",b); getch(); }


How do you check address of char variable?

Use the address-of operator: char c=32; // space character std::cout<<&c<<std::endl;


How can write the name in c plus plus language without using cout statement?

I believe, you can use C-function - printf().


Syntex for accessing data members of the structure in c plus plus?

Use the member accessor (.) operator. struct object { int m_data; }; int main() { object o; o.m_data = 100; std::cout << o.m_data << std::cout; return(0); }

Related questions

Can a conditional operator replace an if statement always?

No. An if statement does not require an elseclause and the expression(s) do not return anything to the caller, whereas the conditional operator always executes one of two expressions and always returns the value of the executed expression back to the caller. The executed expression may be yet another conditional operator, thus allowing simulation of nested ifs and if...else if... else statements.Consider the following example:int x = rand();if( x > 100 ) x = 100;We can achieve the same result with a conditional operator:int y = rand();y = y>100 ? 100 : y;However, if we were to expand this statement to an if statement we would not get the original if statement shown above:int z = rand();if( z > 100 ) z = 100;else z = z;The else clause is clearly unnecessary in this case, so the original if statement would be the statement of choice here.As a general rule, if you can make use of the return value in a conditional operator, and must return one of at least two values, then use the conditional operator. Otherwise use an if statement.


How do you use if then loops in Turbo C for finding if then entered number is even or odd?

The C if statement is not a looping construct, it is used to control conditional branching using expressions. It has two forms:if( expression ) statementWhen expression is nonzero, statement is executed (otherwise it is not).if( expression ) statement elsestatementWhen expression is nonzero, the first statement is executed, otherwise the second statement is executed.The algorithm to determine if a number is odd or even is:Divide the number by 2 and examine the remainder. If the remainder is nonzero, the number is odd, otherwise it is even.In C++, we use the modus operator (%) to determine the remainder of one number divided by another. If the number is X, then the expression (X%2) will evaluate to either 0 or 1. If it is 1 (nonzero), then the number is odd, otherwise it must be even.To print the results for any given number, X, we could use code similar to the following:std::cout


Define Cout in Visual C?

Cout is actually a statement used for outputting strings, the values of variables, and anyother thing that you want to be displayed on the screen. following is the syntax of cout statement. cout<<"String"; cout<<variable/arrays/structure variables; Note: / means that you can use any one of them. cout<<variable1<<variable2<<variable3; cout<<"string 1"<<varibale1<<"string 2"; note: we can use any combination of variables and strings we want. The << operator takes value from the variable and transfer it to cout which sends it to the output device normally the monitor using a stream called the output stream. Thanx, Ghulam Nasir(Khan) NIIT Cout is actually a statement used for outputting strings, the values of variables, and anyother thing that you want to be displayed on the screen. following is the syntax of cout statement. cout<<"String"; cout<<variable/arrays/structure variables; Note: / means that you can use any one of them. cout<<variable1<<variable2<<variable3; cout<<"string 1"<<varibale1<<"string 2"; note: we can use any combination of variables and strings we want. The << operator takes value from the variable and transfer it to cout which sends it to the output device normally the monitor using a stream called the output stream. Thanx, Ghulam Nasir(Khan) NIIT


How you can use two input in a single statement in c plus plus?

cout<<"______": cin >>__>>__; [example cout<<"enter no."; cin>>a>>b; ]


What is the meaning of for in c plus plus?

The for statement introduces a loop, typically a counting loop. The for statement has three optional expressions separated by semi-colons: initial expression(s); conditional expression; and action expression(s). If any expressions are omitted, its semi-colon must still be present. Multiple initial or action expressions may be separated with commas while the conditional expression must be single boolean expression that evaluate zero or non-zero (false or true). The syntax is as follows: for ([initial_expr]; [conditional_expr]; [action]) { statement; } Note that braces are optional when there is only one statement, but required for multi-line statements. Either way, the statement is known as the statement body. The initial expression(s) is/are evaluated before entering the loop. The conditional expression is evaluated before each iteration of the loop. If the evaluation is non-zero, execution passes to the statement body, otherwise execution passes to the statement that follows the satement body. The action expression is evaluated after each iteration of the statement body, before the conditional expression is re-evaluated. For loops are typically used for counting iterations: for (int x=0; x<10; ++x) { std::cout<<x; } In the above example, the loop will iterate 10 times. When the loop is first encountered, x is instantiated and initialised to zero. The conditional expression evaluates true (0<10==true), thus the statement body executes. In this case, the statement body simply prints the value of x. So, after the first iteration, the output will be: 0 The action expression then increments x and the condition is re-evaluated. 1<10==true so the output is now: 01 x is incremented again and again until the output is: 0123456789 At this point, when x is incremented to 10, the conditional expression evaluates false (10<10==false) thus the loop terminates. Note that since x was instantiated within the for statement, it is deemed local to the loop and will fall from scope when the loop terminates. If we wish to retain the value of x, we must declare x outside of the loop. In this case, the initial expression is not required (or we can use it to initialise another variable). int x=0; for (;x<10;++x) { std::cout<<x; } We can also use the statement body to execute the action expression: int x=0; for (;x<10;) { std::cout<<x++; } Note that we use the postfix increment operator in the statement body rather than the prefix increment operator. They both do the same job (incrementing x) but in this example we want the value of x BEFORE it is incremented, hence we use the postfix operator (fetch x, then increment). Although we can use the action to execute multiple actions (separated by commas), using the statement body to perform the actions can often be simpler, especially if the actions are also conditional. If we also elminate the conditional expression, we end up with an infinite loop: int x=0; for (;;) { std::cout<<x++; } This loop will never end because the statement body has no exit condition. However, we can still terminate the loop by placing the conditional expression in the statement body: int x=0; for (;;) { std::cout<<x++; if (x<10) continue; else break; } We can simplify this expression as: int x=0; for (;;) { std::cout<<x++; if (!(x<10)) break; } Note that both continue and break mark the end of an iteration. While break terminates the loop, continue starts a new iteration, but evaluates the for loop's conditional expression (if present) first. By using the statement body to perform conditional expressions, we can create more complex or multiple expressions than might otherwise be possible with the conditional expression of the loop. This makes the for loop extremely flexible. However, if the condition expression is the only portiobn of the for loop that is required, we can simplify things and make our code more readable by using a while loop instead: int x=0; while (x<10) { std::cout<<x++; } Note that while loops only have a conditional expression, which is non-optional. Both for and while can be used interchangeably in many loop structures, however it's best to use the one that makes most sense in the type of loop you are constructing or that aids the readability of your code. One type of loop the for and while loops cannot cater for is one where the loop must execute at least once. For instance, the following loop will fail to execute if x is already 10: while (x<10) { std::cout<<x++; } If we wish to ensure the statement body executes at least once, we must use a do-while loop instead: do { std::cout<<x++; } while (x<10); In this case, the conditional expression is evaluated after each iteration, not before.


How do you use the conditional statement of turbo c?

#include<stdio.h> void main() { int a=10,b=15; clrscr(); if(a>b) printf("%d is the large number",a); else printf("%d is the large number",b); getch(); }


How can you tell whether a given number is even or not?

An even number can be divided by 2 and still be a whole number.ProgrammingYou can use the binury operator % for this purpose, for instance,int even_or_not;cout > even_or_not;if (even_or_not % 2){cout


How do you check address of char variable?

Use the address-of operator: char c=32; // space character std::cout<<&c<<std::endl;


How can write the name in c plus plus language without using cout statement?

I believe, you can use C-function - printf().


What statement is use to make a decisions?

None of them; you may think of the conditional statements, like if-else, for, while, do-while.


What is the definition of nested IF statement?

I believe it would be an if statement INSIDE of another if statement. So, ex. if one condition is TRUE, then the 2nd if statement is executed. could look like: if (colour ==red) if (leaf == maple) cout<< "OMG CANADA!"; else cout<< "Fail."; get it? of course, it can be beneficial sometimes beyond situations where you can simply use the && or operators as well.. but i have PDENG. hope that helps


Syntex for accessing data members of the structure in c plus plus?

Use the member accessor (.) operator. struct object { int m_data; }; int main() { object o; o.m_data = 100; std::cout << o.m_data << std::cout; return(0); }