Programming C: Solidify your skills in the C programming language. Explore concise code examples, grasp key concepts, and build a strong foundation. Start your C programming journey now!
Welcome to the world of Basic C Programming! This repository is designed to provide you with a solid foundation in the fundamentals of C programming. Whether you are a beginner taking your first steps in the programming world or an experienced developer looking to enhance your skills, this repository will guide you through the essential concepts of C programming.
- Variables are used to store data in a program. They have a specific data type (such as int, float, char) and a name that you can assign. You can assign values to variables and perform operations on them.
In C, there are different types of variables (defined with different keywords), for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes- Declaring (Creating) Variables
To create a variable, specify the type and assign it a value:
# Syntax
type variableName = value;-
Format Specifiers: Format specifiers are used together with the
printf()function to tell the compiler what type of data the variable is storing. It is basically a placeholder for the variable value.// Create variables int myNum = 15; // Integer (whole number) float myFloatNum = 5.99; // Floating point number char myLetter = 'D'; // Character // Print variables printf("%d\n", myNum); printf("%f\n", myFloatNum); printf("%c\n", myLetter); // Student data int studentID = 15; int studentAge = 23; float studentFee = 75.25; char studentGrade = 'B'; // Print variables printf("Student id: %d\n", studentID); printf("Student age: %d\n", studentAge); printf("Student fee: %f\n", studentFee); printf("Student grade: %c", studentGrade); // Create a variable and assign the value 15 to it int myNum = 15; // Declare a variable without assigning it a value int myOtherNum; // Assign the value of myNum to myOtherNum myOtherNum = myNum; // myOtherNum now has 15 as a value printf("%d", myOtherNum);
- C has various data types, including int (for integers), float (for floating-point numbers), char (for characters), and more. Each data type determines the range of values and the type of operations that can be performed on the variables.
- Operators are used to perform operations on variables or values. Examples include arithmetic operators (+, -, *, /), assignment operators (=), comparison operators (==, !=, >, <), and logical operators (&&, ||, !).
- Control structures allow you to control the flow of execution in a program. Common control structures in C include if-else statements, switch statements, and loops (such as for, while, and do-while loops).
- Functions are blocks of code that perform a specific task. They allow you to break down your program into smaller, reusable parts. Functions have a return type (void or a specific data type) and can accept input parameters.
- Arrays allow you to store multiple values of the same data type in a contiguous memory block. Elements in an array are accessed using their indices.
- Pointers store memory addresses. They allow you to directly manipulate memory, access variables indirectly, and allocate dynamic memory.
- C provides functions like scanf() and printf() for input and output operations. scanf() is used to read input from the user, and printf() is used to display output on the screen.
- C provides standard libraries that contain pre-defined functions to perform various tasks. Examples include stdio.h for input/output operations, math.h for mathematical functions, and string.h for string manipulation.
- Error handling involves handling and managing errors or exceptional situations that may occur during program execution. This can be done using techniques like error codes, error messages, and exception handling mechanisms.