Posts

Showing posts from March, 2018

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; ...

Tokens In C Programming

What is a token in c language? Token is the basic fundamental unit that makes up C source code after pre-processing.  There are six types of token in C. Keywords: Keywords are special words that are used to give a special meaning to the program and can’t be used as variable and constant. They are basically a sequence of characters that have fixed to mean for example break, for, while, do-while, do, if, int, long, char. Identifiers: Identifiers are the sequence of alphabets and digit, but keyword should not be used as an identifier. Constants: The quantity which does not change during the execution of a program is known as constant. There are types of constant. Variables: Variables are used to give the name and allocate memory space. An entity that may vary data during execution. For example, sum, area, a, b, age, city. String: String is a collection of more than one character. For example, “RAM”, “Meerut”, “Star” String is represented by a pair of double quotes. Ope...

Structure of a c program

Image
Documentation section : The documentation section consists of a set of comment lines giving the name of the program, the author and other details, which the programmer would like to use later. Link section : The link section provides instructions to the compiler to link functions from the system library. Definition section : The definition section defines all symbolic constants. Global declaration section : There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. This section also declares all the user-defined functions. main () function section : Every C program must have one main function section. This section contains two parts; declaration part and executable partDeclaration part : The declaration part declares all the variables used in the executable part.Executable part : There is at least one statement in the executabl...

Hello World - First Program

What is Program ? Program is a set of instructions which can be executed in a specific sequence to get the desired output. Hello World Program is the First Program- hello.c Program: #include <stdio.h> /* Header file */ main() { /* Program execution starts here */ printf ("Hello world"); /* Built-in function - printf() */ return 0; }   1.Comments should be enclosed within /* */ and they won’t get executed. 2.Program execution always start from the main function. 3.printf() is a library function available in “stdio.h” header file. It is used to format and print data. 4.Header file contains the built-in functions and pre-defined variables. ALSo hello.c is the file containing the above program.  Below command is used to compile the c program. gcc <C File Name>  i.e. gcc hello.c

Introduction to C Programming

Founder Of C Programming ~~ Dennis Ritchie Some Introduction to C Programming C language was developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Laboratories.  C was initially designed to develop system software.  Because of its simplicity, flexibility and portability, it is also used to develop application software.  Most of the features in C are derived from "B" programming language.  That is the reason why the new language was named as "C". C is a high level language but it lacks features like garbage collection, object orientation which are usually available in high-level languages. C is a structured programming language.  Because, C provides many features like functions, if statements, loops, blocks etc. Appication Of It Used to develop firmware for micro controllers, operating system, device drivers etc. Major programming languages like PHP, Perl , Python etc. are written in C Used to develop application softwares lik...