C Pointers
Creating Pointers You learned from the previous chapter, that we can get the memory address of a variable with the reference operator &: Example int myAge = 43; // an int variable printf(“%d”, myAge); // Outputs the value of myAge…
Creating Pointers You learned from the previous chapter, that we can get the memory address of a variable with the reference operator &: Example int myAge = 43; // an int variable printf(“%d”, myAge); // Outputs the value of myAge…
Memory Address When a variable is created in C, a memory address is assigned to the variable. The memory address is the location of where the variable is stored on the computer. When we assign a value to the variable,…
User Input You have already learned that printf() is used to output values in C. To get user input, you can use the scanf() function: Example Output a number entered by the user : // Create an integer variable that…
String Functions C also has many useful string functions, which can be used to perform certain operations on strings. To use them, you must include the <string.h> header file in your program: #include <string.h>
Strings – Special Characters Because strings must be written within quotes, C will misunderstand this string, and generate an error: char txt[] = “We are the so-called “Vikings” from the north.”; The solution to avoid this problem, is to use…
Strings Strings are used for storing text For example, “Hello World” is a string of characters. Unlike many other programming languages, C does not have a String type to easily create string variables. Instead, you must use the char type…
Multidimensional Arrays In the previous chapter, you learned about arrays, which is also known as single dimension arrays. These are great, and something you will use a lot while programming in C. However, if you want to store data as…
Real-Life Example To demonstrate a practical example of using arrays, let’s create a program that calculates the average of different ages: Example // An array storing different ages int ages[] = {20, 22, 18, 35, 48, 26, 87, 70}; float…
Get Array Size or Length To get the size of an array, you can use the sizeof operator: Example int myNumbers[] = {10, 25, 50, 75, 100}; printf(“%lu”, sizeof(myNumbers)); // Prints 20 Why did the result show 20 instead of…