Tag c programming language

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…

C Memory Address

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,…

C User Input

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…

C String Functions

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>

C Special Characters

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…

C Strings

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…

C Multidimensional Arrays

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…

C Arrays – Examples

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…

C Array Size

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…