Posts

Increment and Decrement Operator in C

Image
Increment and decrement operators in C The increment operator (++) increments the value of its operand by 1.      x = 10;      x++;  // increments the value of x by 1.  So, the value of x is 11. The decrement operator(--) decrements the value of its operand by 1;      x = 10;      x--;  // decrements the value of x by 1;  So, the value of x is 9.   Both the operators can be placed before or after the operand as shown above and they can be applied on primitive data types like char, int, float, double & they can also be used on pointers and enums. Difference between postfix increment and prefix increment: Example 1: int a, b = 10; a = b++; Value of a is 10 Value of b is 11 In the above expression, the value of b is assigned to a first.  Then, 1 is added to the value of b. Example 2: int a, b = 10 a = ++b; Value of a is 11 Value of b is 11 Here, the value of b is i...

printf() and scanf() functions in C Programming Examples

Image
printf()  and scanf() functions printf() function: It prints the given data on the output screen. Scanf() function: It is used to read input from the keyboard. Format Specifier of Each: printf()- printf("%d", 10);              - prints 10 on the output screen printf("%f", num);            - prints the float value in variable num on the output screen printf("%d and %d", a, b); - prints the value of the integers a and b on the output screen. Suppose, if the value of a is 10 and the value of b is 20.  Then, the output for the below statement would be 10 and 20 printf("%d and %d", a, b); scanf()- Format specifier can be any of the following %u  - unsigned int %d  - int %x  - hexadecimal %o  - octal %f  - float %lf - double %c  - char %s  - string scanf("%d", &v1); - inputs integer value scanf("%x", &v2); - inputs ...

Arithmetic operators in c progamming with example

Image
Arithmetic operators in c Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, division and modulo. Example OUTPUT

Assignment operators in C Language with examples

Image
Assignment operators in C An assignment operator is the operator used to assign a new value to a variable, property, event or indexer element in C# programming language. Assignment operators can also be used for logical operations such as bitwise logical operations or operations on integral  Operands and boolean operands. #include <stdio.h> int main() {       int a, b, c, d, e;  // variable declaration       a = b = c = d = e = 100;  // assign 100 to a, b, c, d & e         a += 10; // a = a + 10       printf("Value of a is %d\n", a);         b -= 10; // b = b - 10       printf("Value of b is %d\n", b);         c *= 10; // c = c * 10       printf("Value of c is %d\n", c);         d /= 10; // d = d / 10       printf("Value of d is %d\n", d); ...

Data Type in C

Image
Data types and format specifiers in c Basic data types available in C programming language are signed char, unsigned char, char, short int, unsigned short int, int, unsigned int, long int, unsigned long int, long long int, unsigned long long int, float, double, long double.  Here, we will see basic data types, their size and range.

What are identifiers in c?

What are identifiers in c? An identifier is a set of characters used to name variables, functions, macros and enums. Valid characters in C language identifiers: Alpha characters[a-z][A-Z] Decimal numbers[0-9] Underscore (_) Dollar symbol($) Valid and invalid identifiers in C language: Numeric character should not be used as the first character of identifer.  Space is not allowed in the name of the identifier.  Below are some of the invalid identifier. Example: 9num, 1val, #val Example of identifiers in C   #include <stdio.h> #define $pi 3.14  // pi is an identifer void _calc_area(int radius) { // calc_area and radius are identifiers       printf("Area of circle: %f\n", $pi * radius * radius);       return; }   int main() {       int $, _, radius; // $, _, radius are identifiers       _ = 5;       $ = 10;       radius = 10; ...

All Keywords in C Programming Language

Image
Keywords in C Programming Language Keywords are those words whose meaning is already defined by Compiler Cannot be used as Variable Name There are 32 Keywords in C C Keywords are also called as Reserved words . Example Of Keyword  #include <stdio.h> void main() {       int i = 0;       const char ch = 'a';       // value of ch is a.  So, case 'a' will be executed       switch (ch) {               case 'a':                       // prints hello world for 3 times                       for (i = 0; i < 3; i++)                               printf("Hello world!!\n");                       break; ...