Wednesday, 8 October 2014

print the values stored in variables

If the declaration of the variables is-
int a=4;
char b='z';
float c=2.3;
to print the values stored in variables-
printf("a=℅d",a);
printf("\nb=℅c",b);
printf("\nc=℅lf",c);
%d belongs to int
%c belongs to char
%lf belongs to long int
Here, the values stored at a,b,c are comes on the place of %d,%c,%lf respectively.
\n is used for new line.
If you write the above in program then in output the data in printf statements will be in three different lines.
The output of above statements will be-
a=4
b=z
c=2.3

Declaration of variables in c programming

If you want to declare variable of type integer then declare it as
int a;
Here your variable is 'a' if type integer. You can store values of type integer to the variable 'a'.
Similarly character variable is declared as
char b;
you can assign values to integer variable as
example-
a=9;
For assigning character  to character variables the character should be written in single quote mark.
example-
b='a';
Without making separate statements you can do declaration and assignment int single statement.
int a=5;
char b='m';
you can also do declaration of multiple variables of same type.
example-
int a,b;
int c=9,d,e=3;
char z='a',y='x';
there are also some different data types like float, double etc.
float type variable can store real numbers
example-
float a=2.2;
float type variables can store integer variables only in real form
example-
float a=2.0;
double type variable can store both integer or frosting type numbers.
example-
double a=2,b=2.2;
There are some other dat noa types like long int etc. Basically int variable can store values from -32768 to 32767. But if you want to store a value out of this range then the variable of data type long int will provide this facility.
example-
long int a=33333;
long int has very big range.
The number of bytes required to store a value of a particular data type in the particular variable of that data type are as follows-
Data type           bytes
char                         1
int                            2
float                         4
long int                   8
double                    8

Print output on screen using C programming

void main()
{
     printf("welcome to C programming");
     getch ();
}
printf is a special function to print the data on output screen. In bracket the data you write between the  double quote marks is printed on screen. The statement ends with semicolon. getch() holds the output string till our next any key stroke.

Tuesday, 7 October 2014

Basic structure of c programming

#include<studio.h>
#include<conio.h>
void main()
{
     .............;
     .............;
}
First two lines are to add the special functions which we are going to use in our program.
main() is our programming function which returning nothing hence void is written. if our function return the value of type integer then function would be int main().
The containt of function is compulsorily written in curly bracket.
In function every statement ends with semicolon.
After writing your programming compile the program. If no error is present then run the program. As a result you will get the desired output.