Your cart is currently empty!

C Programming Basics – Learn Fundamental Concepts – Part 1
C Programming Basics are the foundation for anyone looking to start coding. This guide will walk you through key concepts like variables, data types, operators, and input/output functions to help you build a solid programming base.
Variables and Data Types
In C, a variable is a named storage location that holds a value. The data type determines the size and type of value it can store.
Primary Data Types:
int
:
Stores integer values (e.g., 123, -456)
int myVar = 100;
char
:
Stores single characters (e.g., ‘a’, ‘B’).
char myChar = 'A';
float
:
Stores floating-point numbers (e.g., 3.14f).
float pi = 3.1415926535f;
double
:
Stores double-precision floating-point numbers.
double largePi = 3.14159265358979323862;
Modifiers:
unsigned
:
Allows only non-negative values.
unsigned int uVar = 100; // Cannot be negative
signed
: Explicitly allows negative values (default for int and char).
const
:
Makes the variable’s value constant.
const int MAX = 100; // Value cannot change
Operators
C provides various operators to perform operations on variables and constants.
Arithmetic Operators:
+
(Addition), -
(Subtraction), *
(Multiplication), /
(Division), %
(Modulus).
int sum = 10 + 20; // sum is 30
Comparison Operators:
==
(Equal to), !=
(Not equal to), >
(Greater than), <
(Less than), >=
(Greater than or equal to), <=
(Less than or equal to).
if (a == b) { /* code */ }
Logical Operators:
&&
(Logical AND), ||
(Logical OR), !
(Logical NOT).
&& (Logical AND), || (Logical OR), ! (Logical NOT).
Assignment Operators:
=
(Assign), +=
(Add and assign), -=
(Subtract and assign), *=
(Multiply and assign), /=
(Divide and assign).
int x = 5;
x += 10; // x is now 15
Bitwise Operators:
&
(AND), |
(OR), ^
(XOR), ~
(NOT), <<
(Left shift), >>
(Right shift).
unsigned char a = 5; // binary 0101
unsigned char b = 3; // binary 0011
unsigned char c = a & b; // binary 0001, which is 1
Ternary Operator (Conditional):
Syntax: condition ? result_if_true : result_if_false
int max = (a > b) ? a : b;
Input/Output
C uses standard library functions for input and output.
Output with printf()
:
- Prints formatted output to the screen.
- Format specifiers:
%d
(integer),%c
(character),%f
(float),%lf
(double),%s
(string).
printf("Hello, World!\n"); // Output: Hello, World!
int num = 10;
printf("Number is %d\n", num); // Output: Number is 10
Input with scanf()
:
- Reads formatted input from the keyboard.
- Use address-of operator & for variables except strings.
int age;
printf("Enter your age: ");
scanf("%d", &age); // Note the &
By understanding these C programming basics, you’ll be better prepared to tackle more complex coding challenges. Keep practicing, explore new concepts, and soon you’ll be writing efficient C programs with ease.
Comments
One response to “C Programming Basics – Learn Fundamental Concepts – Part 1”
[…] back to the C Programming Basics series! In Part 1, we covered the fundamentals like variables, data types, operators, and basic input/output […]
Leave a Reply