1 / 5

No-return functions

No-return functions. #include&lt;stdio.h&gt; void printA(void) { printf(“AAAAA<br>”); } void main() { printf(“First line<br>”); printA(); printf(“Second line<br>”); printA(); }. Result. First line AAAAA Second line AAAAA. No-return functions. #include&lt;stdio.h&gt;

telyn
Download Presentation

No-return functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. No-return functions #include<stdio.h> void printA(void) { printf(“AAAAA\n”); } void main() { printf(“First line\n”); printA(); printf(“Second line\n”); printA(); } Result First line AAAAA Second line AAAAA

  2. No-return functions #include<stdio.h> void write(int num) { printf(“The number is %d.\n”, num); } void main() { int a; printf(“Enter a number: “); scanf(“%d”, &a); write(a); printf(“End of program.\n”); } Result Enter a number: 5 The number is 5. End of program.

  3. Return functions #include<stdio.h> int area(int width, int height) { return width*height; } void main() { int a, b, result; printf(“Enter width and height: “); scanf(“%d %d”, &a, &b); result = area(a, b); printf(“Area is %d.\n”, result); } Result Enter width and height: 5 10 Area is 50.

  4. switch(choice) { case ‘a’: result = add(a, b); break; case ‘s’: result = sub(a, b); break; } printf(“Result = %d”, result); return 0; } Return functions #include<stdio.h> int add(int a, int b); int sub(int a, int b); int main() { int choice, a, b, result; printf(“Select operation: \n”); printf(“a for addition\ns for subtraction\n: “); scanf(“%d”, &choice); printf(“Enter two integers: “); scanf(“%d %d”, &a, &b); Result Select operation: a for addition s for subtraction : a Enter two integers: 2 3 Result = 5

  5. int main() { int x = 5; printf(“x is %d when starting.\n”, x); add1(x); printf(“x is %d after add1.\n”, x); add2(&x); printf(“x is %d after add2.\n”, x); return 0; } Call by value VS Call by ref #include<stdio.h> void add1(int a) { a += 10; } void add2(int *b) { *b+=10; } Result x is 5 when starting. x is 5 after add1. x is 15 after add2.

More Related