[Android General] mhrsolanki2020:
CHAPTER 2

​

I can bet you will relate most of the things with C programming , from flowcharts.

When you run an application , it first reserves the memory required for it to run . Lets suppose you are playing a game on computer, "pinball", this game will first reserve the memory locations in the RAM or storage. And then only THE PINBALL game can access those memory locations. The image below depicts is properly.

as you can see above , memory is made up of cells, each cell has its address (0x111 to 0x142 are the adresses, dont worry about the numbers like 0x111 n stuff i just wrote it to show you , the real memory locations are like 2031576,2031577,2031578,2031579 and so on. We will see it in real when we go further down with the chapters :) )

Lets say your computer has a memory from 0x000 to 0x999, and then you open the pinball game , the pinball game needs 32memory cells, and it started getting cells from 0x111 and then reserved till 0x142 so that it can run smoothly , and lets suppose you open another app in backgroud , lets say you opened Calculator, and also suppose Calculator needs 50 cells of memory , then it willl start from 0x143 to 0x193.

These cells are nothing but Bytes.

1Gigabyte = 1000Mega Byte

1MegaByte= 1000 Killobyte

1Kilobyte = 1000 byte

This is what we know right? its wrong :P

1Gigabyte = 1024 Mega Byte

1MegaByte= 1024 Killobyte

1Kilobyte = 1024 byte

What is 1 byte equal to?? :eek: :eek:

1byte = 8bits

NOTE: Google this "1 byte = how many bits"

You will see this at the start , as you can see it works like a converter, just goof around with it have a lil fun n learn mean while.

This was just off topic things, but keep these things in mind while learning C , this is like the general knowledge required for learning C , so now we are starting with Real C programming.

===================================================================================

So now what is variables?

Various Definitions:

"A variable is the name for a place in the computer's memory where you store some data."
"A variable is a way of referring to a memory location used in a computer program. "

Lets not go into theory again , lets talk about a program in which you want to add two numbers.

First of all you want to accept 2 numbers from users , add them and then store it to another variable?

Lets say you accept two numbers 'x' and 'y' from the user , you cant just write x + y, right? cuz x + y what? you will have to use one more variable 'z' and then store the value sum of 'x' and 'y' in it. ie z=x+y

so now here the three variable 'x' , 'y' and 'z' are variables, agreed?

so these variables WILL be stored in memory?

Each of them will use their own memory cells? or to be precise each one of the variable will use a BYTE from memory?

lets say the three memory locations used are 0x200,0x201,0x202

So you can conclude that the NICKNAMES of the memory location 0x200,0x201,0x202 , are 'x' , 'y' and 'z' respectively.

which in other words means the variable 'x' is reffering to 0x200 , so what ever you store in variable x is gonna be stored in the memory cell with address 0x200 and the same with 'y' and 'z' . so the above definitions are true, If you may read it again , you will understand better . Still you dont know what is DATA in this right? we will talk about it in a while.

What are constants?

The value of a variable is constant.

lets talk about the above program again , the variable x, y and z.

The user inputs the number 2 and 4,

so x = 2 , y = 4 and as these numbers are supposed to add and the answer is stored in z , so z=6.

now the value of x will change from program to program , if i make another program , i can use variable x and it may have a different value.

But the VALUE of value of variable , (2, is the value of x) this will never change, 2 will remain 2 , it wont ever mean 3, like 2=3 or something.

Hence it is a constant. This constant is stored in memory. The image below depicts is clearly.

============================================================================

Lets get in actoin?

So lets download the compiler now.

So the compiler we gonna use is DJGPP, it it like command line GCC (GNU C Compiler) , we will write program in notepad++, and then save it and then open up command prompt and then compile it from there and then we will get an .exe file .(dont worry if you arent getting it, everything will be taught )

Links:

DJGPP

Notepad++

How to download things?

For DJGPP:

select these fields:

The selection of Operating system may change according to your OS. If on Windows 7/vista select windows XP in that os section.

then click on tell me which files to download .

then download each of the zip file .

NOTE : If you are on linux then you have gcc compilers already, google it how to use it.

For notepad++:

go to the link above , then click on download button on left botom panel:

then:

.

===========================================================

Put the downloaded files from DJGPP in a folder named DJGPP.

now open the note pad plus plus exe and install it ..

then copy the DJGPP folder to C drive:

now open notepad++

and then write the name of the files in that DJGPP folder in the notepad++ (write unzip32 and then the file name):

and then save it as DJGPP.bat (dont forget to write .bat in that DJGPP folder..

if you have done the downlaod the way i have said and you have 8 files in the folder then copy this and paste in notepad :

unzip32 bnu2211b
unzip32 djdev203
unzip32 faq230b
unzip32 gcc472b
unzip32 mak3791b
unzip32 pakk023b
unzip32 rhid15ab
unzip32 txi412b

now go to DJGPP folder and open this DJGPP.bat file.. it will extract things for you..

now go to start menu , right click on my computer then click on properties:

now follow the instructions in the screen shots below(in some screen shots i have show the PATH in note pad, its jst to show you the path in bigger font. you need not write it on notepad):

click on advanced system properties, for windows xp users, you will have a box opened like the image below , click on advanced tab , for vista users IDK i never used Windows vista goof arround with it you will find what to do..

click on environment variables

click on path and then click on EDIT .

Note that in the path , there should be a ':' semicolon , then write c:/djgpp/bin;%PATH% , then click on ok.

now click on new

write these things in the Variable name and variable value , click on ok , then again ok then again ok. and you will be done..

now we have set up our Compiler .

Now lets write our first C program, just to check whether the compiler is running or not.

copy this and paste it in notepad++ ,

#include<stdio.h>
void main()
{
printf("Hello XDA!!!");
}

now save it with the name hello.c , dont forget to write ".c" at the end.

now open command prompt ,

write

cd desktop

then write

gcc hello.c

then write

a

if you got something like this then you are done.. if you got a error like Gcc is not an internal comand or something.. you messed it up , try the steps above from setting the environment variables.. and still you fail then you mail me at c.helpline2020@gmail.com

NOTE: Dont worry , we were just checking if its working or no , m gona teach you to use command prompt soon :D trust me , the boring part is over now. Its all the fun now :good: