compiler:
A compiler is a software that converts a source code written in programming language into target computer language. A c program must have a compiler to run the source code.
Introduction to c
Every c program begins inside a "main" function. Whenever the program executes the main function is called first and later we can call functions inside the main function..A c program consists of three parts header, body and conclusion. We can include library functions into the program through the header by using a hash tag.
let's look into a small program:
#include<stdio.h>
int main()
{
printf("Welcome to c");
getchar();
return();
}
Now look into the program, On the top of the program we have #include header file. stdio stands for standard input and output functions. Everything inside the main function is the body of the program. Everything we used inside the program should follow the syntax rules.
Variables:
Input and data should be placed in variables. There are several types of variables. When are telling the compiler that you are declaring a variable you have to declare the data type of the variable along with the name of the variable. Different data types are char, int and float..
A variable of type char stores a single character, whereas type int stores the integers(Numbers without decimals). Float stores the numbers with decimals.
To declare a variable one must follow the syntax used to declare in c programming i.e, <data_type> <variable_name>;
Examples of some variable declarations:
int x;
int a,b,c,d;
char letter;
float the_float;
Reading an input:
sample program to read an input
#include<stdio.h>
int main()
{
int this_is_a_number;
printf("Please enter your number:");
scanf("%d", &this_is_a_number);
printf("You entered %d",this_is_a_number);
getch();
return 0;
}
No comments:
Post a Comment