Variable& Data Type Operator in C
Variable& Data Type Operator in C
Variable:
In C programming, a variable is like a named container that holds data during your
program'
Syntax of Variable :
underscore (_).
o Can contain letters, numbers, and
underscores.
o Cannot be a reserved keyword in C
data_type variable_name;
int num ;
int (integer):
2. float (floating-point):
3. double (floating-point):
4. char (character):
Operator in C programming :
. Arithmetic Operators:
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulo - remainder after division)
Assignment Operators:
= (assignment)
+= (add and assign)
-= (subtract and assign)
*= (multiply and assign)
/= (divide and assign)
%= (modulo and assign)
. Comparison Operators:
These operators compare values and return
either 1 (true) or 0 (false) based on the
comparison result. Common examples include:
== (equal to)
!= (not equal to)
< (less than)
> (greater than)
<= (less than or equal to)
>= (greater than or equal to)
Logical Operators:
These operators combine conditional expressions and are used
for making decisions in your program. Common examples
include:
Breakdown:
condition:This is a boolean expression that
evaluates to either true or false.
expression_if_true: This is the expression that
gets evaluated and returned if
the condition is true.
expression_if_false: This is the expression that
gets evaluated and returned if
the condition is false.
Lets go through one Example :
#include <stdio.h>
int main() {
int age = 25;
int isAdult = (age >= 18) ? 1 : 0; // Ternary
operator usage
if (isAdult) {
printf("You are an adult.\n");
} else {
printf("You are not an adult.\n");
}
return 0;
}