Posts

Logical Operators

Logical operators in c language:-   !   ( logical negation - NOT )    && ( logical AND )  | | (logical OR) An expression containing logical operator returns either 0 or 1 depending upon whether expression results true or false.   1. && ( logical AND ):- If  both operands are true or non zero, condition become true or 1. Otherwise condition become false or 0.  Suppose A and B are operands,      If A=2 and B=5, A && B is true or 1.      If A=2 and B=2, A && B is true or 1.      If A=2 and B=0, A && B is false or 0.      If A=2 and B=5, A>0 && B<0 is false or 0.      If A=2 and B=5, A>0 && B>0 is true or 1.     Example:- #include<stdio.h> #include<stdlib.h> int main() {     int A = 2;     int B = 8;     printf(...

Arithmetic operators

Arithmetic operators are: * (Multiply), /(divide), %(Modulas)- It's priority is most + -          It's priority is least. i) Multiplication Operator : This operator multiplies two operands. If in any expression if there is * (multiplication) and + (Addition). Then according to precedence rule * (multiplication) is first solved. If in arithmetic operators, operators are the same then it is solved from left to right. i.e its associativity is left to right. Program #include <stdio.h> #include<conio.h> int main() {     int a;     a=2*3;     printf("Answer of multiplication operator is %d",a);     getch(); } Output: Answer of multiplication operator is 6 ii) Integer divide Operator : Examples:  2/3 ? = 0 Instead of 0.6. 13/2 =6 instead of 6.5. Because in c language if any operations are performed between two integers. then, our result will be in integer. Program:...

Unary Operator

What is a Unary Operator? Unary Operators are the operators which require only one operand. While binary operator requires two operands and tertiary requires three operands. Unary operators are: +, -, ++, --, sizeof() 1) + and -   Note: (+) and (-) are not of addition and subtraction but it denotes only sign of operator as positive or negative. Ex. +1, +2, +3... -1, -2, -3... 2) ++ and -- It seems to be  ++ (two plus-plus), But it is a single operator. It is called the increment operator . Increment operator are of two type: i) Pre increment ii) Post increment The meaning of both the increments is the same. i.e To add +1 in  any value x++ or ++x; or to increase the value by 1. x++ is x=x+1 where x is a variable. Example: 7++ output is 8 25++ output is 26 program: (Pre-increment)  #include <stdio.h> #include <conio.h> int main() {     int x=7;     ++x;  / /Whe...

Identifiers

What is identifier ?       In C language identifiers are the names given to variables, constants, functions, and user-defined data. An identifier or name is a sequence of characters invented by the programmer to identify or name a specific object. Rules for identifiers:- The first character must be an alphabet or underscore. All characters must be alphabetic characters, digit or underscores. Only the first 31 characters are significant. You can not use a keyword. Must not contain white space. Identifiers names must be unique.   Some examples:- people_number monthly_pay tool_4 box_4_weight maths_2_sum  When we declare a variable or any function in C language program, to use it we must provide a name to it, which identified it throughout the program. example:-            int sum_1 = "que1" ; Here,  sum_1 is name or identifiers for the variable which store the value "que1" in it. ...

Operators

What are the operators and the operands? Example:  1+2=5 Operators: Here the symbol (+) which adds 1and 2 is called as an operator. So, the operator is the symbol used to perform the operation. Operands: Here 1 & 2 are called as operands or data. What operators can do? An operator performs the operation for this they need data or operand. Without any operands, operators can not perform their operations. There are several types of operators in C language/mathematics. Before we understand Operators in C. First let us understand what is arithmetic instructions? Arithmetic instruction: It contains variables on the left side of = (Assignment operator) and variable names. Constants on right side of = (assignment operator). An instruction which is used to manipulate(to change/control) data using operators, is known as Arithmetic operators. Example:  5+10*3 45 or 150 If you solve from left to right then your answer will be 45. But if you sol...

Symbolic constant

Defining Symbolic constant: A symbolic constant value can be defined as a preprocessor statement that is used in the program as any other constant value. When you include the header file with the help of the keyword define, the constant is declared it is called symbolic constant. Define symbolic constant : #define symbolic_name value of constant The symbolic name of variable or constant then after giving space put the value which wants to put. Other examples : #define PI 3.141593 #define TOTAL 100 You can also use this in as a global variable PI-Symbolic constant whose value is 3.141593. When the program is preprocessed, all occurrences of the symbolic constant PI are replaced with the replacement text 3.141593 Symbolic constant in C program : #define PI 3.141593 #define TRUE 1 #define FALSE 0 Symbolic constants are the constants represented by symbols... Constants are values that don't change throughout the program execution Example: #include<stdio...

Declaration of variable

After deciding a suitable name for the variable, we have to declare them to the compiler. What does declaration do in c program? It tells the compiler what the variable name is. It specifies what types of data the variable will hold. There are two types of declaration of variables. Primary declaration User-defined declaration 1. Primary declaration: -        In primary type declaration, A declaration statement begins with the type, end by the name of one or more variables. A declaration statement must end be with a semicolon. Syntax of declaration sentences. Syntax :    data_type variable_1, variable_2, .....,variable_n;  Declaration of multiple variables of the same data types can be done in one statement. For Example,               int a;               int b;               int c; can be also written as     ...

Popular posts from this blog

Getting input in C

Unary Operator