ساختار ها در زبان C Structures in C.

Slides:



Advertisements
Similar presentations
5.5 and 5.6 Multiply Polynomials
Advertisements

Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
For(int i = 1; i
1 Records C++ Structs Chapter 14 2 What to do with records?  Declaring records  Accessing records  Accessing the field of a record  What is a union?
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
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.
Exercise 2.
1 Programming Structures COMP102 Prog. Fundamentals, Structures / Slide 2 2 Structures l A Structure is a collection of related data items, possibly.
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
 2007 Pearson Education, Inc. All rights reserved. Structs as Function Arguments and Results  Arrays – Pass by referance  Struts – the same way as the.
Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
Data Management and File Organization
1 CSE1301 Computer Programming Lecture 24 Structures (Part 2)
Today, I will learn the formula for finding the area of a rectangle.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
 Review structures  Program to demonstrate a structure containing a pointer.
1 Principles of Programming I Note Set #12. 2 Semester Overview Functions Character File I/O Arrays Pointers and Dynamic Memory Allocation Characters.
3-4 Lesson 3-4 Example 1 Use the formula A = ℓ w to solve for ℓ, length. The area of the rectangle is 72 square yards. Its width is 9 yards. What is the.
Solving systems of equations with 2 variables
Areas involving rectangles and triangles For each rectangle you must be able to spot the length and width For each triangle you must be able to spot the.
Distribute and Combine Like Terms Applications. What is the area of the following shape? 5 2x-3 1.
Basic Measurement.
Lesson 13-2 Pages Adding Polynomials. What you will learn! 1. How to add polynomials.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Struct 1. Definition: Using struct to define a storage containing different types. For example it can contain int, char, float and array at the same time.
Computer Engineering 2 nd Semester Dr. Rabie A. Ramadan 3.
Super Intense Area Problem Assignment. What are the steps for solving this type of problem given at the end of the note video? 1.
Structures 142 S -1 What is a structure? It is a collection of possibly different types Name the collection Name the components For example: a student.
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
A B The points on the coordinate plane below are three vertices of a rectangle. What are the coordinates of the fourth vertex? C.
Surface area of a cylinder Imagine a cylinder opened out Rectangle Circle.
PERIMETERS What is the Perimeter of a shape. What is the Perimeter of this rectangle? What is the Perimeter of this rectangle? 5cm 15cm.
LESSON 2 Basic of C++.
ALGEBRA JEOPARDY Review of Factoring.
Structures.
Structures Lesson xx In this module, we’ll introduce you to structures.
S. Kiran, PGT (CS) KV, Malleswaram
Barlogik Mathsbee Round 3: Each question has a diagram made up of a number of green CONGRUENT (identical) rectangles. To answer the question you must.
Pointer to a Structure & Structure Containing a Pointer Difference Lesson xx  In this presentation, we will illustrate the difference between a pointer.
CS150 Introduction to Computer Science 1
اشیاء در جاوا Java Objects
Objective - To identify how perimeter and area relate.
Algebraic Expressions
Use the substitution method to find all solutions of the system of equations {image} Choose the answer from the following: (10, 2) (2, 10) (5, - 2) ( -
How to find the area of a parallelogram.
CS148 Introduction to Programming II
Structure As Function Arguments
Chapter 1: Introduction to Data Structures(8M)
King of the Mountain.
Introduction to Programming
EECE.2160 ECE Application Programming
Page 6 Original Expression: Step 1: Step 2: Step 3:
Web Service.
12.4 p 471 a) double[] number = {1.05, 2.05, 3.05, 4.05, 5.05};
Structure.
EECE.2160 ECE Application Programming
Function Overloading.
Structures In C Programming By Rajanikanth B.
Adding and Subtracting Radicals
C Programming Lecture-14 Unions
Structure (i.e. struct) An structure creates a user defined data type
Jeopardy Rational Exponents. Laws of Exponents Polynomials Q $100
Structures in c By Anand George.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Area and Volume How to … Calculate the area of a square or rectangle
Programming Fundamental
Programming Fundamental
Presentation transcript:

ساختار ها در زبان C Structures in C

مقدمه از ويژگی های مهم زبان C در ++C تحت عنوان Class هستند ساختار ها مجموعه ای از داده های غیر همنوع هستند که به گونه ای ممکن است با هم مرتبط باشند به هر یک از این داده ها عناصر ساختار می گویند

فرم کلی اعلان ساختار struct <struct-name>{ <type> <element-name1>; <type> <element-name2>; <type> <element-name3>; …… <type> <element-name n>; }; چون تعریف ساختار یک دستور مستقل است باید حتماً ; آورده شود نام دلخواه است مطابق دستورالعمل زبان نحوه تعریف عناصر ساختار همانند متغیر های عادی است

مثال: ساختاری را تعریف کنید که اطلاعات یک دانشجو را در خود ذخیره نماید Struct student { Long int id; //شماره دانشجویی حداکثر 8 رقم Char name[20]; // نام دانشجو Float average; // معدل کل دانشجو Int age; // سن دانشجو Char gender; // ‘M’ مرد= “F” جنسیت دانشجو زن= };

با تعریف هر ساختار در واقع یک نوع داده جدید تعریف می کنیم مثل student پس از تعریف ساختار می توان انرا مانند یک متغیر معمولی انرا تعریف نمود: Student s; این دستور متغیری بنام s از نوع student تعریف می کند اکنون متغیر s شامل کلیه عناصر تعریف شده در ساختار مورد نظر می باشد و C بصورت خود کار حافظه لازم را به ساختار اختصاص می دهد

نحوه دسترسی به عناصر ساختار از عملگر dot (.) استفاده می شود ابتدا نام متغیر ساختاری و بدنبال آن نقطه و سپس نام عنصر مورد نظر مثال مقدار دهی به عناصر متغیر ساختاری s: s.id=84122030; strcpy((s.name,”reza”); s.average=17.64; s.age18; s.gender=‘m’ عناصر هر ساختار را می توان مانند متغیر های معمولی در ارگومان توابع مورد استفاده قرار داد: gets (s.name); scanf(“%f”,&s.average); printf(“age=%d”,s.age);

نکات مهم ساختارها مقدار دهی اولیه به ساختار مجاز است (مشابه مقدار دهی ارایه ها) Student s={83201012, “ali”,16.90, 19, ‘M’}; 2. می توان هنگام تعریف ساختار همزمان چند متغیر از آن نوع ساختار راتعیین کرد Struct rectangle { Int x,y; // مختصات شروع Int length, width; } r1, r2; 3. استفاده از عملگر = برای دو متغیر ساختاری مجاز است به شرط اینکه هر دو از یک نوع باشند مثال: Rectangle r1, r2; R1.x=r1.y=0; R1.lenght=10; R1.width=20; R2=r1 با این دستور عناصر متغیر ساختاری r2 دارای همان مقادیر عناصر متناظر در r1 خواهند بود 4. چنانچه تعریف ساختار در خارج از کلیه توابع انجام گیرد ساختار سراسری می شود و در تمام توابع شناخته شده است (البته تعریف ساختار در داخل توابع بصورت محلی متداول نیست

ارایه ای از ساختار ها