C Programming Code Examples
Learn C Language
Logical Operators in C Programming Language
Logical Operators in C
An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming. These operators are used to perform logical operations and used with conditional statements like C if-else statements.
&&
Called Logical AND operator. If both the operands are non-zero, then the condition becomes true.
||
Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true.
!
Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.
/* logical operators in C language */
#include <stdio.h>
main() {
int a = 4;
int b = 23;
int c ;
if ( a && b ) {
printf("Line 1 - Condition is true\n" );
}
if ( a || b ) {
printf("Line 2 - Condition is true\n" );
}
/* lets change the value of a and b */
a = 2;
b = 8;
if ( a && b ) {
printf("Line 3 - Condition is true\n" );
} else {
printf("Line 3 - Condition is not true\n" );
}
if ( !(a && b) ) {
printf("Line 4 - Condition is true\n" );
}
}
C program code input week number(1-7) and print day of week name using switch case. C program to find week day name using switch case. Input day number from user. Store it in
This Code is very simple and a good example of using conditional statement (if-else) in an iteration (i.e. for loop). We shall initiate a for loop having some finite iterations and check
Filename, device, inode, protection, number of hard links, user ID of owner, group ID of owner, device type, total size, blocksize for filesystem I/O, number of blocks allocated,
C programming language code to search specified file for specified character. See if correct number of command line arguments. Opening file for input and look for character.
This C program is used to find the sum of the 'Harmonic Progression Series'. H.P stands for harmonic progression. Harmonic progression is a progression formed by taking reciprocals
C Program increments every element of the array by one & print array. We need to add 1 to all the elemnts of the given array. After adding 1 to all the elements of an array print