UPDATED:

How To Make A Simple Calculator By C Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... Happy Coding.......... This blog is under construction!!!!
Namecheap.com
Showing posts with label introduction to c. Show all posts
Showing posts with label introduction to c. Show all posts

Tuesday, December 27, 2016

Scope of validity


In C, you can declare local and global variables. There are therefore two different areas of validity. The scope of validity specifies where a variable exists and is "visible".

A local variable (or constant) is declared within an instruction block, such as a function. So far we have declared only local variables in the main () function. These are only valid in this function. That is, another function (if you had one) can not access these variables. The same applies to constants. For a different function, these variables and constants are non-existent.

It is important that you initialize local variables before using them! The value that local variables have is not predictable! In other words, at the beginning, there is some value in a local variable. This can be 0, but also any other value. And that is rarely desired.

A local variable is only valid (available) when the function in which it was declared is called. If the function is terminated, the variable is no longer available. This is why it is advantageous for local variables if they immediately assign a value to their values ​​when they are declared so that no unpredictable results are obtained. The best way to initialize each variable is 0.

By default, 0 (zero) is used to initialize global variables. Global variables are valid throughout the program, therefore in all functions. Write the declaration as far as possible at the top of the source code to keep the overview.

#include <stdio.h>

Int global_variable; / * Is initialized with 0 and is valid throughout the program * /

Int main ()
{
  Int local_variable; / * Is initialized with an unpredictable value and is only valid in main () * /

  Printf ("local:% d \ n", local_variable); / * Output the value of the local variable * /
  Printf ("Global:% d \ n", global_variable); / * Output the value of the global variable * /

  Return 0;
}

For a detailed explanation of printf (), keep your eyes on our next post. Here, only the following is anticipated: The% d ensures that an integer is output. In this case, the first parameter specified after the text (string). A newline is generated with \ n.

You can declare local variables that have the same name as declared global variables. In this case, you always "see" the local variable, as the following example shows:

#include <stdio.h>

Int i = 10; / * Global variable i with the value 10 * /

Int main ()
{
   Int i = 50; / * Local variable which is also called i /
                 / * I is initialized to 50 * /

   Printf ("value of i:% d \ n", i); / * I output * /

   Return 0;
}


Local Variable

The variables declared inside the function are automatic or local variables.
The local variables exist only inside the function in which it is declared. When the function exits, the local variables are destroyed.
int main() {
    int n; // n is a local varible to main() function
    ... .. ...
}
void func() {
   int n1; // n1 is local to func() fucntion
}

Global Variable

Variables that are declared outside of all functions are known as external variables. External or global variables are accessible to any function.

#include <stdio.h>
void display();

int n = 5;  // global variable

int main()
{
    ++n;     // variable n is not declared in the main() function
    display();
    return 0;
}

void display()
{
    ++n;     // variable n is not declared in the display() function
    printf("n = %d", n);
}

Output
n = 7
Suppose, a global variable is declared in file1. If you try to use that variable in a different file file2, the compiler will complain. To solve this problem, keyword extern is used in file2 to indicate that the external variable is declared in another file.
Test it yourself!

Friday, February 26, 2016

DATA TYPE,VARIABLES,INPUT AND OUTPUT

DATATYPE: C has five types of basic Data.such as int,double,float,char and void.Today we are going to learn int Type data programming.int stand for integer.Integers are 0,1,2,3......

VARIABLES: A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.




The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore.Upper and lowercase letters are distinct because C is case-sensitive.
Now write this program on your compiler:

code:

           #include <stdio.h>

           int main()
           {
               int x,y;
               x = 5;
               y = 6;

               printf("%d",x);

           return 0;
           }

Output: 5



Description of the program: Here i wrote int x,y;int stand for integer and here i declared two variables x & y.You can declare many variables.You can not write variables like 1x,$a,#x,+y,show-ans etc.You can use this operators or signs or numbers (1,$,+,#) after characters.And you can use show_ans.
In printf function i used "%d" for showing integer which i mentioned after it.

Can you do summation,subtraction,multiplication and division by C?See in my next post.
Thanks for being with coder mania BD.

First program in C

We are going to write our first program in C a compiler.I write a program like this:

Code:

/*This is our first program.*/

#include <stdio.h> 


int main()         

{
    printf("Hello Worid.");
    
return 0;
}

Output is: Hello World.

coder mania bd

When i run this program it shows me "Hello World".

Why and How it works?

At first i wrote a comment between /*.......*/.The compiler do not read any comment in a program.You can write comment in a program for making a program easily readable to others or our next development.You can write single line comment and multi-line comment.For single line comment you have to use // this and for multi-line comment you have to use /*........*/ this.

After that we used #include <stdio.h>.#include means i linked something in this program from C library.Actually i linked a header file.C has many header file.All file have specific uses.The <stdio.h> file is for input and output operation.<std(standard)i(input)o(output).h(header)> .

Then i wrote int main().int means integer and the main() is a function.C has many functions but main() is the principle function for C language.

{...statements.....},The second brackets keep the statements.printf("Hello Worid."); this is a statement.Every statement must have to end with ; semicolon.

Now printf("Hello World."); printf is a function.It helps the program to give output.After the printf,there are  two quotation mark between two braces.Between the quotation mark you can  write anything which you want to show on your console.

return 0;This statement tells the program to end his works.

This was our first program.Many programmer start their programming with this program Hello World.If you face any problem to understand then feel free to contact us.You can comment here or visit our Facebook page Coder Mania BD and Facebook group .
Thanks for being with coder mania bd.

Friday, February 19, 2016

The Basic structure of C.


If you want to be a good programmer,You need to know the basic structure of a language (C).

In C basically there are two parts.Like Include Files Part & Main function () part.


Include files like header files.There are many header files stored In C language library.such as #include <stdio.h>, #include <math.h>,#include <conio.h> etc.
Main function usually declare the variables and call the library functions,user defined functions.Every C program starts with main ().You can not think C without main ().In C,there can be many functions along with main ().Every function has specific work.
“Other functions” part is under main () function.Main () function call different types of library functions like, clrscr(),getch(),sqrt(),printf(),scanf(). And also call user defined functions.


Now I am going to describe a program sections.


You can write comments in the document section.To write single line comment use // and for multiline comment use /*……*/.
You have to link a header file in the link section.Header files define the library functions and keywords.Header files executes the program.
Symbolic constants are defined in the definition section.
Global variables are declared in the Global variable declaration section.Global variables can be used in several function.
Main function is a function where a program call the library functions and user defined functions.C program starts from compile and executes main() function.

Main function consist of two parts:

(1)Declaration part:- It declare all variables which are used in executable part.

(2)Executable part:- Executable part contains with  minimum one statement.


There is a Demo program for you:


#include <stdio.h>
int main ()
{
    printf("Hello World.");

 return 0;



Be continue.......

Wednesday, February 17, 2016

INTRODUCTION TO C


coder mania bd
C is a high level (2nd generation) structural language. With C you can solve scientific and mathematical problems. Beside this C has enormous uses like designing operating system, program developing, execute a database etc.

To start C what you will need?

At first you need a computer. A text editor.
I recommended you to use CODE BLOCK.It is a fantastic text editor.
I use it. 

you can download it from here:

For windows user :
go-->codeblocks.org-->downloads-->windows
For linux :
go-->codeblocks.org-->downloads-->linux
For Mac user :
go-->codeblocks.org-->downloads-->mac
If you face any problem to run this software in your computer then contact us through comment or join our group https://www.facebook.com/groups/codermaniabd/
Thanks for being with Coder Mania BD.
Namecheap.com

Popular Posts