فصل سوم. 2 Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute...

Post on 13-Dec-2015

215 views 2 download

transcript

Cمفاهیم اولیه زبان فصل سوم

2

1.14 BASICS OF A TYPICAL C PROGRAM DEVELOPMENT ENVIRONMENT

• Phases of C++ Programs:1. Edit2. Preprocess3. Compile4. Link5. Load6. Execute

Program is created in

the editor and stored

on disk.Preprocessor

programprocesses the

code.

Loader puts program in

memory.

CPUtakes eachinstruction and

executes it, possibly storing

new data values as the program

executes.

Compiler creates object code and

storesit on disk.Linker links the

objectcode with the

librariesLoader

Primary Memory

Compiler

Editor

Preprocessor

Linker

 

Primary Memory

.

.

.

.

.

.

.

.

.

.

.

.

Disk

Disk

Disk

CPU

Disk

Disk

c:کلمات رزرو شده زبان

مثال ساده:

C STANDARD HEADER FILES YOU MAY WANT TO USE

استاندارد توابع :مهمترین stdio.h – file and console (also a file) IO: printf, open, close, read, write, scanf, etc.

string.h - string and byte manipulation: strlen, strcpy, strcat, memcpy, memset, etc.

errno.h – defines errno used for reporting system errors

math.h – math functions: sin, exp, floor, sqrt, etc.

time.h – time related facility: asctime, clock, time_t, etc.

: خروجی و ورودی دستورات

# include < stdio.h >void main (){const float pi = 3.14 ;float r,p,s;printf (" please enter reduce : \n ") ;scanf("%f",&r);p = 2*pi * r ;s = pi * r *r ;printf (" The S = %f , The P = % f " , s,p) ;while(1);}

مثال: برنامه ای بنویسید تا شعاع دایره را از ورودی

بخواند و محیط و مساحت آنرا حساب کند و نمایش دهد.

//9 simple program# include < conio.h >#include <stdio.h>void main(){int a=21,b=10,c;c=a%b;printf("a=%d ,b=%d c=%d \n",a,b,c);int x=0xf0,y=0x0f;printf(" %x ,%x , %x ,%x ",x&y,x|y,y<<4,x>>4);getch();}

; از آدرس float a[5]تمرین :فرض کنید محل ذخیره آرایه 0x0100 شروع می شود.تعیین کنید تا چه آدرسی به آرایه

است)AVR ATMEGA 16فوق اختصاص می یابد.(میکرو

آرایه های دو بعدی:

یعنی آرایه ای از آرایه های یک بعدی

مثال:

فرض کنید دو آرایه یک بعدی بشکل زیر داریم:

Int a[3]={1,2,3}

int b[3]={4,5,6}

حال می خواهیم انها را بصورت یک آرایه دو بعدی نمایش دهیم:

int c[2][3]={{1,2,3},{4,5,6}}

C(0,0)=1 C(0,1)=2

C(0,2)=3

C(1.0)=4 C(1,1)=5

C(1,2)=6

روش تعریف آرایه های دو بعدی:

[ اسم آرایه ] تعداد ستون ][ تعداد سطر نوع متغیرها

Main)(

{

Int i=0;

HERE:

i;++

If (i<10)

Goto HERE;

Printf(“THE MAX value of i is:%d “,i);

Getch;)(

}

مثال:

را عددی که بنویسید تابعیتوان و بگیرد ورودی 3از

نماید چاب و حساب انرا

تابعی: 2مثال عدد دو که بنویسید

و بگیرد ورودی از رارا آنها بزرگترین

نماید چاب و تعیین