کلاس های متغيرها در C 1- کلاس متغيرهای اتوماتيک auto int x = 10; /* x is global auto int x = 10; /* x is global void main( ) { void main( ) { int x = 25;

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

For(int i = 1; i
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
1 Lab 4 Westfield High School APCS LAB 4 Parameters, apvectors, structs.
Class 15 - Overhead 11Object Oriented Programming Using C #define t_circle 1 #define t_rectangle 2 struct circle_shape {short type; double x,y; double.
EC-241 Object-Oriented Programming
مهدی آذرنوش مبحث ششم : آرایه ها و رشته ها حسابگری الگوریتمی.
برنامه سازي پيشرفته 1 4. using System; //A class represents a reference type in C# class Fraction { public int numerator; public int denominator; public.
10 Little Gifts First one for you health Second for you luck.
Let’s repeat the ordinal numbers!
Type Title Here for Tic-Tac-Toe Type names of students in group here.
در جامعه، افرادي که موقعيت و مسؤليت خود را مي‌دانند از راحتي و امنيت بيشتري برخوردارند هر کلاس از جامعه، مجموعه‌اي از امکانات و تواناييهاي مجاز برخوردار.
int getThird(int *arr){ return arr[3]; } In all these examples “n” is the size of the input e.g. length of arr O(1) And what two things are wrong with.
Problem: Given an array of positive integers, find a pair of integers in the array that adds up to 10 (or indicate none exist). Your code should be as.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
Bubble Sort Notes David Beard CS181. Bubble Sort for Strings Double pass algorithm to sort a single dimensional array. Inner loop “bubbles” largest element.
CS Oct 2006 Chap 6. Functions General form; type Name ( parameters ) { … return value ; }
CS 1400 March 21, 2007 Odds and Ends Review. Reading to the end of a file Example test.txt : … Suppose we need.
Local, Global Variables, and Scope. COMP104 Slide 2 Functions are ‘global’, variables are ‘local’ int main() { int x,y,z; … } int one(int x, …) { double.
دسته بندی زبانها بر حسب نوع زبانهای با نوع : (ايستا : ترجمه) – (پويا : تفسير) تفسيری : Snobol، Apl، Awk، Javascript var kate=“hi” var sam=200 val l=10.25.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
 Review structures  Program to demonstrate a structure containing a pointer.
Scope Accessibility of Names. Review We’ve seen that C++ permits a programmer to declare names and then use those names in a manner consistent with their.
Christ the Bread of Life
10 Little Gifts The First for your health The Second for your luck.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Public class Edo1 { private static double euler(double y, double h, double t, Derivada d) { return y + h * d.f(y, t); } public static void euler(double.
Multiplying Common Fractions Multiplying next Using the Corn Bread © Math As A Second Language All Rights Reserved.
Class 4 (L34) u Constructors u Default Constructor u Example of Default Constructors u Destructors u Constructors Are Called in Global Scope u Constructors.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Functions Sujana Jyothi C++ Workshop Day 2. Functions 3 Parameter transmission modes pass by value (default) pass by reference (&) pass by const reference.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
The Angels Club You are invited to be part of THE ANGELS.
The Angels Club You are invited to be part of THE ANGELS of the Keys.
Data Types Modifiers Base data type Size Sign signed int 2 B unsigned float 4 B short double 8 B long char 1 B.
A: A: double “4” A: “34” 4.
Stoichiometry Project Pd5 3/18/10. Problem If 4.1 grams of Cr is heated with 9.3 grams of Cl 2, what mass of CrCl 3 will be produced? next.
Example 1 Writing Powers Write the product as a power and describe it in words. a. 44= to the second power, or 4 squared 9 to the third power,
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Functions Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
CPSC 252 Tables / Maps / Dictionaries Page 1 Tables, Maps and Dictionaries A table (or map or dictionary) is a collection of key/value pairs. In general.
Fractions Part Two. How many halves are in a whole? 2 1/2.
1 C++ Classes and Data Structures Course link…..
C++ Lesson 1.
Zoom In Game.
ㅎㅎ Fourth step for Learning C++ Programming Namespace Function
مبانی کامپیوتر و برنامه سازی
Reserved Words.
Recursion.
Review Operation Bingo
Click to edit Master text styles
null, true, and false are also reserved.
Stack Memory 2 (also called Call Stack)
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Click to edit Master text styles
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
Student #7 starts with Locker 7 and changes every seventh door
Click to edit Master text styles
ОПШТЕСТВО ТЕМА: МЕСТОТО ВО КОЕ ЖИВЕАМ Скопје
class PrintOnetoTen { public static void main(String args[]) {
Observing how the machine acts
Local, Global Variables, and Scope
Days of the Week Monday Tuesday Wednesday Friday Thursday Saturday
Programming Language C Language.
Click to edit Master text styles
CS150 Introduction to Computer Science 1
The Solar System.
Consider the following code:
Click to edit Master text styles
Presentation transcript:

کلاس های متغيرها در C 1- کلاس متغيرهای اتوماتيک auto int x = 10; /* x is global auto int x = 10; /* x is global void main( ) { void main( ) { int x = 25; int y = ::x ; int x = 25; int y = ::x ; { int z = x ; int x = 38; int t = ::x ; int z = x ; int x = 38; int t = ::x ; t = x; t = x; } int z = x; int z = x; دوره زندگی : ( شروع حيات : ورود به بلاک ) ، ( خاتمه حيات : اتمام بلاک )

2- کلاس متغيرهای ايستا 2- کلاس متغيرهای ايستا long double cal ( ) { long double cal ( ) { static bool first = true ; static bool first = true ; static long double v; static long double v; if (first == true) { v = v + 0.5; first = false; return v;} if (first == true) { v = v + 0.5; first = false; return v;} void main( ) { void main( ) { long double x = cal ( ); long double x = cal ( ); long double y = cal ( ); long double y = cal ( ); } }

مثال بعدی از ايستا : مثال بعدی از ايستا : int f(int k) { int f(int k) { static int z = 2; static int z = 2; z = z + k; z = z + k; return z; return z; } } void main ( ) { void main ( ) { cout << f(1); cout << f(1); cout << f(2); cout << f(2); } }

مثال استفاده از متغير ايستا در اشتراک حافظه مثال استفاده از متغير ايستا در اشتراک حافظه struct A { struct A { int j ; int j ; static int k ; static int k ; }; }; int A :: k = 10; int A :: k = 10; void main ( ) { void main ( ) { A a1; a1.j = 2 ; a1.k = a1.k * 2; A a1; a1.j = 2 ; a1.k = a1.k * 2; A a2; a2.j = a2.j * 2; a2.k = a2.k * 2; A a2; a2.j = a2.j * 2; a2.k = a2.k * 2; cout <<a2.j<<a2.k; } cout <<a2.j<<a2.k; }

void create(void); : مثال بعد void create(void); : مثال بعد int first = 1; int first = 1; void main ( ) { void create(void) { void main ( ) { void create(void) { int second = 2; int fifth = 5; int second = 2; int fifth = 5; static int third = 3; static int sixth = 6; static int third = 3; static int sixth = 6; create ( ); int seventh = 7; create ( ); int seventh = 7; int fourth = 4; } int fourth = 4; } } } ترتيب ايجاد (1) و حذف (2) متغيرها : ترتيب ايجاد (1) و حذف (2) متغيرها : first(1)-second(1)-third(1)-fifth(1)-sixth(1)-seventh(1)- first(1)-second(1)-third(1)-fifth(1)-sixth(1)-seventh(1)- seventh(2)-fifth(2)-fourth(1)-fourth(2)-second(2)-sixth(2)- third(2)-first(2) seventh(2)-fifth(2)-fourth(1)-fourth(2)-second(2)-sixth(2)- third(2)-first(2)

3- کلاس متغيرهای خارجی 3- کلاس متغيرهای خارجی /*file1.cpp /*file2.cpp /*file1.cpp /*file2.cpp double x = ; extern double x; double x = ; extern double x; double f(double y) { extern f(double); double f(double y) { extern f(double); return y ; void g(double z) { return y ; void g(double z) { } x = f(z); } x = f(z); void main ( ) { } void main ( ) { } … } }