Posts

Showing posts with the label variables

C: Using scanf to assign more than one value.

Image
Short demonstration of how scanf can be used to accept input for more than one variable assignment. In this case, an integer and a double are assigned. Note what happens when a double is entered for an integer, and vice versa.

C: Simple Usage Of Variables.

Image
 https://github.com/pereiradaniel/beginning_c/blob/master/ch2/vars.c // vars.c // Daniele Grech Pereira, 02 November 2022 // Demonstrate and explain briefly the simple usage of variables. #include <stdio.h> int main(int argc, char* argv[]) { int num, // // Variable declaration, also a definition*. num2; // Declare a second int variable for user input. num = 777; // Arithmetic assignment statement**. // FOR DEMONSTRATION ONLY!! // Uncomment these two lines to see what happens when you try to print a var that has not been initialized. printf("If you try to print num2 before it has a value assigned, you will retrieve the last data that was stored at that memory address!\n"); printf("num: %d, num2: %d\n", num, num2); printf("Enter a number to assign to num2: "); scanf(" %d", &num2); printf("Accessing int variable num: %d\n", num); // *** printf("Accessi...