C Program
C Program
Integer constants:-
A integer constant is a numeric constant
(associated with number) without any fractional or
exponential part.
There are three types of integer constants in C
programming:
1. decimal constant(base 10)
2. octal constant(base 8)
3. hexadecimal constant(base 16)
Sometimes, it is necessary to use characters which cannot be
typed or has special meaning in C programming.
For example: newline(enter), tab, question mark etc. In order to
use these characters, escape sequence is used.
For example: \n is used for newline. The backslash ( \ ) causes
"escape" from the normal way the characters are interpreted by the
compiler.
Escape Sequences Character
1. \b Backspace
2. \f Form feed
3. \n Newline
4. \r Return
5. \t Horizontal tab
6. \v Vertical tab
7. \\ Backslash
8. \' Single quotation mark
9. \" Double quotation mark
10. \? Question mark
11. \0 Null character
An operator is a symbol which operates on a
value or a variable. For example: + is an
operator to perform addition.
C programming has wide range of operators to
perform various operations. For better
understanding of operators, these operators can be
classified as:-
1. Arithmetic Operators
2. Increment and Decrement Operators
3. Assignment Operators
4. Relational Operators
5. Logical Operators
6. Conditional Operators
7. Bitwise Operators
8. Special Operators
Operator Meaning of Operator
+ addition or unary plus
- subtraction or unary minus
* multiplication
/ division
% remainder after
division( modulo division)
1. C programming has two operators increment
++ and decrement -- to change the value of an
operand (constant or variable) by 1.
2. Increment ++ increases the value by 1
whereas decrement -- decreases the value by 1.
3. These two operators are unary operators,
meaning they only operate on a single operand.
eg. Int. a=10, b=100
++a = 11
--b = 99
An assignment operator is used for assigning
a value to a variable. The most common
assignment operator is =
Operator Example Same as
= a=b a=b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
A relational operator checks the relationship
between two operands. If the relation is true, it
returns 1; if the relation is false, it returns value
0.
Relational operators are used in decision making
and loops.
Operator Meaning of Operator Example
== Equal to 5 == 3 returns
0
> Greater than 5>3
returns 1
< Less than 5 < 3 returns 0
!= Not equal to 5 != 3
returns 1
>= Greater than or equal to 5 >= 3
returns 1
<= Less than or equal to 5 <= 3 return 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main( void )
{ …
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
#include <stdio.h>
int main()
{
int firstNumber, secondNumber,
sumOfTwonumbers;
printf("Enter two integers: ");
scanf("%d %d", &firstNumber, &secondNumber);
sumOfTwoNumbers = firstNumber +
secondNumber;
printf("%d + %d = %d", firstNumber, secondNumber,
sumOfTwoNumbers);
return 0;
}
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
printf("You entered: %d", number);
return 0;
}
#include <stdio.h>
int main()
{
double firstNumber, secondNumber, temporaryVariable;
printf("Enter first number: ");
scanf("%lf", &firstNumber);
printf("Enter second number: ");
scanf("%lf",&secondNumber);
temporaryVariable = firstNumber;
firstNumber = secondNumber;
secondNumber = temporaryVariable;
printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber);
printf("After swapping, secondNumber = %.2lf", secondNumber);
return 0;
}
Instructions which define general loops (for, while instruction etc...) or jumps
(goto, etc...). General loops will not be treated as instructions, but using
another programming mechanism, for the reason we want to control their
execution.
Some less useful operators &&, ||, are not defined since they can easily be
replaced by the logical operators. Similarly, shift operators << or >>, which
corresponds to some multiplications with eventually other mask manipulation
are avoided. Furthermore, complex affectations, e.g. +=, *=, etc... or
incremental x++ operators which can be considered as compact expression
builded from other defined operators are not introduced.Again, all these
operators could have been defined, but they will not be very useful here. From
a programmer point of view, the main use of these operators are the fact they
might lead to more efficient compilations. This is nowadays not very true,
because usual compilers indeed optimize the code even if the programmer
has not written it in a very compact form. For instance, x=x+1 will obviously
be implemented, as x+=1 or even x++.
The indirect operator * and reference operator & is not to be defined since we
do not manipulate pointers explicitly.
The conditional operator expr ? val1 : val0 is not defined, since this is
redundant with the instruction.
Any Queries??????????
Thank You For Watching...