Goto statement and Condition operators

Hello friends today C for fun brings you the new concept or the generally used statements used in our C languages or send text the not most commonly used frankly speaking go to statement is generally avoid it but you must know the concept of it.


As the name suggests go to fix symbolises that the point has to move to a specific location when the code or the line is executed. The pointer move to a specific locations specified in the program generally go to statement is used for coming out of paper nested loops when there are a number of loops implemented in our program we need to come out of the loop in one go so what to do? 

In this case the go to statement help you it give the functionality to the user to come out of the nested loop in simple one step.


Latest now understand the go to statement in a bit details. Blow is the explanation of the go to statement you may go through the statement and if you find any problem or query you make payment down the answer would be there in no time.

Goto statement


the goto statement is a jump statement which is also called as unconditional jump statement, in this tutorial by c4fun we are going to learn some basics about it and a very shortcut manner

·         C support goto statement to branch unconditionally from one point to another in the program.

·         The goto statement requires a label in order to identify the place.
·         A label is only valid name and must be followed by a colon like,
Goto label;                          label: statement;
Label: statement                   goto label;
Forward jump                      backward jump


#include<stdio.h>
Void main()
{
Int I,j;
for(i=1;i<2;i++)
{
for(j=1;j<=3;j++)
{
If(i==2&&j==3)
goto out;
}
}
out:printf(“out of last loop”);
}



Generally go to statement is avoided by users it is not preferred to use it the reasons are listed below you may go through the reasons but it is not the hard and fast rule that you should avoid that but in general you must avoid it !

Reason to Avoid goto Statement

The goto statement gives the permission to jump to any part of the program but, makes the logic complex
# it considered a harmful construct and a bad programming practice.
# it can be replaced in a program by break and continue statements.

The better option in C language in place of go to statement is the replacement by break and continue statement you can use these in place of go to statement and can make the efficient program which you were making earlier with the go to statement it it



Let us know understand about the some conditional operator used in C languages


Conditional operators are like if and else only but they are a little bit different in syntax they are also called ternary operators is the use 3 values.


More can be learnt from the below a detailed information has been there for the users who want to understand the difference between if and else and the conditional operator syntax .


Condition operators



    It is known as ternary operators since they take three arguments.exp1?:exp2?:exp3?
·         If exp  1 is true or 1 then exp 2 is executed otherwise exp 3.
·         The limitation of this operator is only one statement can occur.
·         Example

Int a,b,c;
C=((a>b?)0:1)

Other examples

Void main()
{
int a,b,c;
              printf(“enter value of a,b,c”);
scanf(“%d%d%d”,&a,&b,&c);
a>b>c?printf(“a is largest”):printf(“c is largest”):b>c?printf(“b is largest”):printf(“c is largest”)
getch();
}



Now when you have gone through the conditional operators and the go to statements now you know everything about the syntax. how to use. it share your views comment down below the the experience or the problem you faced?
Did you make any program with the go to statement and then change it with the if else or the anyany other like break Or continue?





Share the program among your friends and help them to understand the difference between go to statement and the conditional operators use of them as in different locations.
 C4fun is based on sharing is caring concept.
Help us to share and care thank you
Keep learning
Keep coding....

No comments

thanks for reading and sharing.I hope it would help you!!!!

Powered by Blogger.