Saturday 12 December 2015

Variable declaration

Variable declaration and Data Types:

                   In C language, variables are used as the repository to store some value. The value may be unchangeable throughout the execution of the program or may be a temporary variable that can change its value in the course of program execution (based on user input or dependencies on other variables).
    
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
printf("The value of a is %d and b is %d",a,b);
 getch();
}

Tha above program simply stores two integer values in two variables 'a' and 'b' and displays the stored value when executed.


The first line of the main function depicts the variable declaration. Two variables named 'a' and 'b' with integer data type is declared. The data type is the one that says which type of data the variable holds.

int - integer
fload - decimal
char - characters
long int - long integers
double - numbers with 8 values after decimal point.

These are the normally used data types. Other than this many rarely used data types are there,  that we  will discuss on upcoming chapters.

Normally an integer will occupy 2 bytes but in modern compilers it is 4 bytes of memory. char datatype occupies 1 memory byte and float will occupy 4 bytes and double 8 bytes of memory.

%d - integer data
%c - character type data
%f - float type of data

 The printf function in the above program uses these specifiers to print the value of variable. However the variable name should be written in same order separated by comma.

SYNTAX:

 printf("%d %d", variable1, variable2);

if you want to print the second variable first,  then 

 printf("%d %d",variable2,variable1);

    These specifiers used inside double quotes always takes the value of corresponding variables.


Thank you.... :)
  





        

Thursday 10 December 2015

First program - Hello Universe!!!

Greetings.....

Starting with the first program!!!

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello Universe!!!");

getch();
}

The above program is the one that is very basic.

Compile the above program for errors. If there is no error then run it. The output will be like this 



#include<stdio.h>  
                   This is called as headerfile that is mandatory and must for all the programs that are being written in C language. <stdio.h> depicts that the C compiler has some standard input and output functions that are to be called to use in this program and .h represents that it is a headerfile. 
     
   To use printf() and scanf() functions these headerfile is mandatory.

stdio - Standard Input Output

#include<conio.h>
                 This is another headerfile that represents Console input output. This is used in compilers like turbo c++. But the modern compilers does not need this.
                  
        To use clrscr() and getch() this headerfile is mandatory to be written before main function.

clrscr() - used to clear the previously executed output from the output console screen
getch()- used to view the  console screen. without this the screen will not be static.

If clrscr() is not used then the second execution of the program will result like,

 
 Look in to that the previous output is not cleared
 

void main()
              void main() is called as the main function that is must for all C programs. The compiler first checks from this main function once the program is executed. Thus this is the starting of any C program. Function should return a value. If it is not going to return any value then "void" keyword is used before main().  

 The same program can be written like  
 

#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
printf("Hello Universe!!!");
return 0;

getch();
}

 Here instead of "void", "int"(data type)  is used. This means the function returns an integer value.

So, the return 0; is used in the last. Both will give the same result.

printf("xyz");

        Printf() is a library function that is used to display the output for the given input. Whatever you give inside the double quotes will be displayed in the console screen. Semi colon must be used at the end for all the statements used inside the functions except for conditional statements. This represents the end of the statement inside the function.

 In the next post, we will see about the variable declaration.


Thank you.......... :)
 

HEAD START .............

Wlcome to my blog....

 Lets start our programming tutorials with basic C language.

C language is the very basic that every programmer or developer crosses in his career. Without knowing C programming it is not that much easy to learn the advanced languages like Java or python or whatever it is.

C language is the middle level language. Because it is the form of input given to the machine,  that can be understandable by human and uses the common English words rather than using binary values.

Lets speak about those theories and all in coming sessions and now we can start directly with the programming...

All you need to do is to download a C/C++ compiler and to install  it in your Personal Computer or whatever it is. Many advanced compilers are available now in internet. I starter learning C from the basic Blue Screen C++ compiler and only minor changes are made in the modern compilers in terms of functionality.



Click on the below link to download C/C++ compiler. If you have one already then just check if it is working properly without any crashes.

http://sourceforge.net/projects/turbocforwindows-9/


Thank U.......... :)