How this code works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How this code works?

#include<stdio.h> #include<conio.h> void main() { char s[]="This is my character array"; int a=5; printf(a>10?"%s":"%s",s); } Output:This is my character array

26th Oct 2021, 5:47 PM
Ur-Wellwisher
Ur-Wellwisher - avatar
4 Answers
+ 3
a>10? ā€œ%sā€ : ā€œ%sā€ This is a ternary operator. An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c. One can read it aloud as "if a then b otherwise c". In this code is a bit useless because it will print the string anyways.
26th Oct 2021, 6:24 PM
Guillem Padilla
Guillem Padilla - avatar
+ 1
Ur-Wellwisher yes this is correct u can use as many u want
27th Oct 2021, 3:22 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
According to standard your program will give you errors becz void main is no longer supportable in c cpp u can use int main and with return int u need to return any value at the end Inside body u have define one char array and in print statement u have written a>10 if this will be ture then fist case will be execute otherwise second one will be execute this is ternary operator if u dont know about it u can read . %s work as a format specifier in c language if u have to print any value then u need to use format specifiers for Integer value%d for char %c for string %s and simply s will be printed on your Console
26th Oct 2021, 6:24 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Is this print statement is correct? If so how many we can use it?
27th Oct 2021, 3:18 AM
Ur-Wellwisher
Ur-Wellwisher - avatar