Posts

Showing posts from 2017

Data Types in C Programming

There are four basic data types supported by C. Table lists the basic data types with their size in bytes and the range of values. Type Size In bytes   Range   char   1 -128 to +127   int   2   - 32768 to +32767 float 4 3.4e-38 to 3.4e+38 double 8 1.7e-308 to 1.7e+308 The C provides different qualifiers like signed , unsigned , short and long. By applying the qualifiers to the basic data types, we can change the range of our data type as per need. Table lists the various data types available by applying the qualifiers to the basic data types with their size and range of values.  Type Size in bytes Range char(signed char) 1 -128 to +127 unsinged char 1 0 to 255 int(signed int) 2 -32768 to +3

Variables

The variables represent the quantities which changes with the time. Each variable identified by a unique identifier in a program called variable name. The variables are used to store values which changes continuously. The length , breadth , area  etc. are examples of variables which we have used earlier programs.               The ANSI rules for variables names are as follows.               1. Only uppercase and lowercase letters, digits and underscore can be used.               2. Variable name always begins with letter.               3. Only first 32 characters are significant.               4. Keywords can not be used.               5. Variables name are case sensitive. The Count and count are two different variables. The care should be taken while choosing the names of variables, so that the names are appropriate to the quantities to be represented and meaningful. Consider the following variable names. average count maximum temp_calc temp_fahr The unders

Constants

Image
The constants  are the values which never changes. The C uses following types of constants. Integer constants :                 Integer constants represent the whole numbers. They uses digits 0 to 9 and optional sign + or - before the number. The following are examples of valid integer constants. 123 -23 65535 0 +85                 The space, comma and other special symbols are not allowed. The following are examples of invalid integer constants. 10,000  $500 15 780 Real Constant :                 Real Constants represent the numbers with fractional parts i.e digits after decimal point. They are used to represent contiguous quantities like temperature of day. The following are examples of valid real constants. 0.0005 -0.123 +248.0 215. .78  Character Constants : Character constants represent single character and are always enclosed in single quotes. The following are examples of valid character constants. 'A'         'a'      

Identifiers

The identifiers are user defined names used in programs for providing names to variables, arrays and functions. The identifiers are made up of letters(uppercase and lowercase), digits and underscore(_). For Example, int max ; //max is an identifier which have datatype integer int max2; //this is second identifier of same datatype string max_3; //you can also use identifier like this with different datatype and underscore float 4max ; //you can not declare identifier like this this will generate an error The C is case sensitive and hence the uppercase and lowercase letters are not treated as same. For Example, int max=20 ;// this is a different variable which assigns a value 20 to max int Max=10 ; //this is different variable which assigns a value 10 to Max Identifiers also used to identify functions. For Example, int Add() ; //this is a Function which is created for addition of two integer; Program Aim : - This Program will help you to understand how the functio

Keywords

The keywords are special words used in C programming having specific meaning. The meaning of these words can not be changed. They are also knows as reserve words. Reserve words can not be used as identifiers. Keywords in C Programming auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while Description of all Keywords in C auto The auto keyword declares automatic variables. For example: auto int var1; This statement suggests that var1 is a variable of storage class auto and type int. Variables declared within function bodies are automatic by default. They are recreated each time a function is executed. Since, automatic variables are local to a function, they are also called local variables. To learn more visit C storage class . break and continue The break statement makes program jump out of the innermos

Flowchart

Image
Flowchart Flowchart can said as a graphical representation of an algorithm. The only difference is you need to draw symbols in flowchart in the place of writing steps. 1. Graphical representation of any program is called flowchart. 2. There are some standard graphics that are used in flowchart as following: Figure: Start/Stop terminal box Figure: Input/output box Figure: Process/Instruction box Figure: Lines or Arrows Figure: Decision box Figure: Connector box Figure: Comment box Figure: Preparation box Figure: Separate box    Write a algorithm to find out number is odd or even.

Algorithms

Definition: - Algorithm is a stepwise solution to any problem which is used in programming to create a knowledge of steps to write a program. A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem. As Algorithm goes in sequence it is written in steps for example: - Write a algorithm to find out number is odd or even? Ans.  step 1 : start This Represents Starting of Algorithm. step 2 : input number This is for input which is inserted by user or given in program by default. step 3 : rem=number mod 2 rem is defined as variable which is storing the Result of number mod 2 step 4 : if rem=0 then                print "number even"            else                print "number odd"            endif This step contains the whole solution to find the number is odd or even step

Structure of Simple C Program

A simple C Program: Below C program is a very simple and basic program in C programming language. This C program displays “Hello World!” in the output window. And, all syntax and commands in C programming are case sensitive. Also, each statement should be ended with semicolon (;) which is a statement terminator.   1 2 3 4 5 6 7 8 #include <stdio.h> int main ( ) {    /* Our first simple C basic program */    printf ( "Hello World! " ) ;    getch ( ) ;    return 0 ; } Output: Hello World! C Basic commands Explanation #include <stdio.h> This is a preprocessor command that includes standard input output header file(stdio.h) from the C library before compiling a C program int main() This is the main function from where execution of any C program begins. { This indicates the beginning of the main function. /* _ some _ comments _ */ whatever is given inside the command “/*   */” in any C program, won’