how to swap values in variables in c
#include <stdio.h>
#include <stdlib.h>
int main()
{
//initialize variables
int num1 = 10;
int num2 = 9;
int tmp;
//create the variables needed to store the address of the variables
//that we want to swap values
int *p_num1 = &num1;
int *p_num2 = &num2;
//print what the values are before the swap
printf("num1: %i\n", num1);
printf("num2: %i\n", num2);
//store one of the variables in tmp so we can access it later
//gives the value we stored in another variable the new value
//give the other variable the value of tmp
tmp = num1;
*p_num1 = num2;
*p_num2 = tmp;
//print the values after swap has occured
printf("num1: %i\n", num1);
printf("num2: %i\n", num2);
return 0;
}
Also in C:
- declare integer c
- _CRT_SECURE_NO_WARNINGS
- c random number
- how to find the ith row of pascal's triangle in c
- sdl texture error out of memory
- grep with color highlight
- table fixed header
- hello world program
- how to go to top of file in vim
- WARNING: QA Issue: rdepends on
- typedef in c
- vector aleatorio sin repetir
- cmd command to hide folder
- char to int c
- c shift array left
- c isdigit function
- Declaring Variables in C
- objective c swizzle method
- c defined value sum
- refresh a chromebook terminal
- how to print the elements of a linked list in c
- how to login to docker inside kubernetes cluster
- how to limit tiktok on mikrotik
- How to make a printf in c