Showing posts with label C Program. Show all posts
Showing posts with label C Program. Show all posts

Monday, December 8, 2014

Variable and Data Type in C

  No comments    
categories: 


Variable and Data Type in C
Put simply a variable is what the program used to store a value in computer's memory

Data Type

Data Types of variables tell the computer to store different types of values such as number, text, true/false....They also inform
the computer to reserve the different memory's spaces for those variables.

Here is a table of the data types of variables in C that can be used.


Declaring Variables

Before a variable can be used to store temporary data in computer memory. it must be declared.
To declare a variable in C programming language you must write down its name immediately after its data type.

Example:

int a; //declare a variable a to store integer value

you can declare more than one variable of the same type on a single line by separating them with commas (int i,j;)

Assigning values to variables

Example:

int a=2;
char b=A;

you can also write as shown below

int a;
a=2;
char b;
b=A;

In C a variable can also be a signed variable or an unsigned variable. Signed means that it can have negative numbers and unsigned means it can't but unsigned gives a variable a greater positive range.

Example:

unsigned int i;
To give the variable a smaller or bigger rane respectively. you need to put short or long keywords.

Example:

short int i;

Levels of declaring variables

You can declare variables at two levels--local and global levels. A variable declared at the local level is in a function and it can only be used by the code in that function.
By declaring the variable at global level the variable can be used by code in any function in the program.
You need to declare a global variable outside any function above the main function.

Example:

#include <stdio.h>
#include <stdlib.h>

int x;//Global variable
void printd();
int main(int argc, char *argv[]){
int y=20;//Local variable
x=10;//assign value to x variable
printf("Value of y is:%d\n",y);//using y variable
printd();
system("pause");
return 0;
}
void printd(){
printf("Value of x is:%d\n",x);//using x variable
}

String data type

A string is a type of variable that can store multiple words. You can declare a string in two ways.
The first is to declare it as a string pointer by using Char the means that it points to the first character of the string.

Example:

char *s= "C programming";
The second way is to declare it as an array of character which yo must set a size when you declare it.
you have to use the strcpy function to assign values to it.
You must also include the string header file to be able to use the strcpy function.

Example:

char s[20]

Strcpy(s,"THEARA");






Thursday, November 27, 2014

C Basic Syntax and Comments

  No comments    
categories: 
C Basic System

In the previous tutorial, you learned to create your first program in C programming language, in the page, you will learn the basic syntax of C.

#include <stdio.h> and #include <stdlib.h> are statement written down to include stdio and stdlib header file that will allow you to get the user input from keyboard and display text on the screen.
C program will start from the main nethod;
int main(int argc, char *argv[]) 
{
// C statements
}

**Return 0; statement will tell the operating system that your program ends here without any error. a value that is not zero represents the abnormal program temination.
**printf is a commend used to prirnt text on the screen.

Comments

Like other language, in C programming language, comments are used to explain the code written or to exclude the part of code from being excuted. 
There are two types of comments C programming:

1.. To make comments for a single line, you will see the // sign. you can place only a single line of text after the single line comments sign. for the normal text, it should be the description of the code. if you place a line of code after single comments, the code won't be executed.
2.. To make comments for multiple lines, you will place the text or code in the /*...*/ block. 
See the example below:
#include <stdio.h>
#include <stdlib.h>
/* Your first program will print the words Hello World on the screen.*/
int main(int argc, char *argv[]) 
{
printf("Hello World\n")//print Hello world on the screen.
system("pause");
return 0;
}





The Result 



Wednesday, November 26, 2014

What is C Programming?

  No comments    
categories: 
What is C Programming????
C  Programming is structured programming languages that was first developed around 1972 and it is still popular today.
One of reasons that contribute to the popularity of C is machine independence. Software developed with C can run on many
different hardware and software platforms.

The first Programming!!
In this C programming language tutorial, you will start with the basic knowledge required to get up and running with C.
Then you will learn some basic and advanced concepts of C programming language (along with workable example and samples projects) 
including C Variables and data types, operators and expressions, conditional statements or decision making, loop or repetitions, function, array, structure, string manipulation methods, memory management, file stream and sample program source code.

To develop software with C programming language, ou will need one of C editors, In this tutorial I recommend you to download and install Dev-C++ 5.1 or the latest version.




How to Create New Projects!!!
After install it ready 

Now open Dev-C++ editor, create a new empty console project of you choice and type the C code below.





#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) 
{
printf("Hello World\n");
system("pause");
return 0;
}


This is a Result 



 Free Soft Here about Dev v5.1