Skip to content

Instantly share code, notes, and snippets.

@SaicharanKandukuri
Last active May 12, 2021 07:45
Show Gist options
  • Save SaicharanKandukuri/552e277ee09c457d246ad8ddc4d28439 to your computer and use it in GitHub Desktop.
Save SaicharanKandukuri/552e277ee09c457d246ad8ddc4d28439 to your computer and use it in GitHub Desktop.
way to make a c code only exit when any key/enter key is pressed

Holding program is important when it dircetly running its compiled binary for example in windows compiled file are in .exe format that means they are applications and can be launched by a click At this contition conio.h has the thing we require we getch(); to hold output

Example

This is a c code example to use pointers in swapping and adding two variable

  • we use getch at last to hold the process
#include <stdio.h>
#include <conio.h>

int plus(int *a, int *b)
{
    int sum=*a+*b;
    return sum;
}
int __swaper(int *a, int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}

int main()
{
    int a,b;
    char xit;
    printf ("a = ");
    scanf("%d", &a);
    printf ("b = ");
    scanf("%d",&b);
    printf (" calcutating ..... \n ");
    printf ("The Sum is %d \n", plus(&a,&b));
    printf ("Swapped Values \n");
    __swaper(&a,&b);
    printf ("a = %d \n", a);
    printf ("b= %d \n", b);
    printf ("Press enter to exit ... \n");
    getch();
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment