answersLogoWhite

0

Explain goto and return in c?

Updated: 12/18/2022
User Avatar

Wiki User

11y ago

Best Answer

A return statement is used to transfer the program control flow to the function that has called the current function under execution. If the function is main, then the program returns the control flow to the operating system. The syntax for return statement is:

return return-type;


A goto statement is used to transfer the control flow to a particular labelled statement, not necessarily back to the calling program. There are somerestrictionson using a goto statement. For eg: the goto statement should not skip any variable declarations. The use of goto statement is usually considered as a bad programming practice. The syntax for goto statement is:


goto label_name;

..

..

label_name: statements;

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Explain goto and return in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c for goto statement?

AGAIN: puts ("c"); goto AGAIN;


Why do you need goto statement in C programming?

There are some cases when it makes your code simpler; for example a 'return' in the middle of a function can be replaced by a 'goto RETURN', where RETURN is a label near to the end of the function.int myfunction (void){FILE *f= NULL;char *buff= NULL;int rc= 0;...if (error_condition) return -1;if (error_condition) { rc= -1; goto RETURN; }...RETURN:if (f) fclose (f);if (buff) free (buff);if (debug) fprintf (stderr, "leaving function with rc=%d\n", rc);return rc;}


Why goto in c is a bad command?

A 'goto' statement immediately moves the execution of code to another part of the program. This makes the code difficult to follow and to debug. It is better practice to use If-then-else constructs to structure the program code.


What are different types of control statements available in c?

1. goto, break, continue, return 2. if-else, switch-case-default 3. while, for, do-while


How do you write a program using goto statement?

int main (void) { puts ("Hello"); goto LABEL; LABEL: return 0; }


How many arithmetic statement in c?

Only one: expression. Yes, in C expression is one of the statements. Some other statements are: if, do, goto, while, for, switch, break, continue, return, NULL-statement, compound-statement.


What is go-to unconditional in c plus plus?

An unconditional goto is a goto that has no associated conditional expression. The following example demonstrates conditional and unconditional goto statements. int x=rand(); if (x) goto label_1; // conditional goto (when x is non-zero) else goto label_2; // conditional goto (when x is zero) label_1: // ... goto label_3; // unconditional goto (jump past label_2) label_2: // ... label_3: // ...


What is branching instruction?

im am sick of all of this mess save me now send this to the next ten people this is a actual question answer it dumb dumb In language C these are: goto, return, continue, break


List of command used in c language?

It's easy: there are no commands in C, but a few statements (such as: expression, if, else, switch, while, do-while, for, break, continue, return and goto), and countless library functions (like printf, malloc and fopen).


What is looping statement in turbo c?

while, for, do-while (and perhaps goto)


Which statement is not frequently used in C plus plus?

The goto statement.


What is the C program to check whether a given character is vowel or not using if else?

#include<stdio.h> main() { char key; clrscr(); printf("Enter the key"); scanf("\n %c",& key); if (key>='A' key<='Z' )&&(key>='a' key<='z') { printf("%c is an character \n",key); } else { printf("%c is not character",key); } getch(); }