Structure ការណែនាំអំពី Structure

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Introduction to Programming Lecture 39. Copy Constructor.
Pointer to Structure. Structure variable can be access using pointers int a=10,*p; Here p  is an integer type pointer variable, p can hold the address.
Structures Spring 2013Programming and Data Structure1.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Arrays Write a program that first reads in 20 integers and then asks the user whether they want to display all the even integers or all the odd integers.
EXERCISE IN CLASS CHAPTER 3. PART 1 IDENTIFIER SCENARIO 1 o record1 o 1record o file_3 o return o $tax o Name o name and address o name-and-address o.
C Language Summary HTML version. I/O Data Types Expressions Functions Loops and Decisions Preprocessor Statements.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Structs. Structures We already know that arrays are many variables of the same type grouped together under the same name. Structures are like arrays except.
Structures and Functions Ghulam Nasir Khan. Important /\/otes Programming is a fundamental course of IT as well as BICSE, so it will be very difficult.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Array, Structure and Union
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Welcome to Concepts Pointer Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )PGT(CS) KV JHAGRAKHAND.
Welcome to Concepts of Pointers. Prepared by:- Sumit Kumar PGT(Computer Science) Kv,Samba.
Structures (L30) u Syntax of a struct Declaration u Structure Variables u Accessing Members of Structures u Initialize Structure Variables u Array of Structures.
Structured Programming Approach Module VIII - Additional C Data Types Structures Prof: Muhammed Salman Shamsi.
DATA STRUCTURE & ALGORITHMS Pointers & Structure.
Structures. Outline Introduction Structure Definitions and declarations Initializing Structures Operations on Structures members Structures as Functions.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
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.
1 Structures. 2 What is a Structure? Used for handling a group of logically related data items  Examples: Student name, roll number, and marks Real part.
Lecture 10: Structures. Outline Introduction Structure Definitions and declarations Initializing Structures Operations on Structures members Structures.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Introduction We will study how to broaden the modeling facilities of C by defining our own data types that represent structured collections of data pertaining.
Chapter 10-1: Structure.
Pointers, Enum, and Structures
LESSON 3 IO, Variables and Operators
TMF1414 Introduction to Programming
Visit for more Learning Resources
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Programming Languages and Paradigms
Functions Dr. Ashish Sasankar. In programming, a function is a segment that groups code to perform a specific task. A C program has at least one function.
Basic notes on pointers in C
DATA HANDLING.
Buy book Online -
Lecture 9 Structure 1. Concepts of structure Pointers of structures
S. Kiran, PGT (CS) KV, Malleswaram
Structures and Union.
Chapter 10: Records (structs)
Pointers  Week 10.
Pointer to Structures Lesson xx
Local Variables, Global Variables and Variable Scope
5th Chapter Pointers in C++.
Dynamic Memory A whole heap of fun….
Introduction to Programming
EGR 2261 Unit 12 structs Read Malik, Chapter 9.
Structures and Union.
Pointers Pointers are variables that contain memory addresses as their values. A variable name refers to a specific value. A pointer contains an address.
Object oriented programming (OOP) Lecture No. 7
Programming Language C Language.
C Programming Lecture-8 Pointers and Memory Management
C Programming Lecture-13 Structures
Structures In C Programming By Rajanikanth B.
Chapter 9: Pointers and String
Character Arrays char string1[] = “first”;
The Stack.
C Programming Lecture-14 Unions
Structures and Union.
READING AND PRINTING MATRICES (with functions)
Structures in c By Anand George.
CSCE 206 Lab Structured Programming in C
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
Arrays and Pointers.
Presentation transcript:

Structure ការណែនាំអំពី Structure ដូចអ្វីដែលអ្នកធ្លាប់បានសិក្សា និងធ្លាប់ដឹងហើយថា array គឺប្រើសំរាប់រៀបរាប់ ឬជាឈ្មោះតំណាងឱ្យក្រុមនៃទិន្ន័យដែលមានប្រភេទទិន្ន័យដូចគ្នា។ ឩទាហណ៍៖ int, float …។ ប៉ុន្តែយើងមិនអាចយក array មកប្រើប្រាស់ ឬតំណាងឱ្យក្រុមនៃប្រភេទទិន្ន័យដែលមានប្រភេទទិន្ន័យខុសគ្នាបានទេ។​ ដូ​ច្នេះយើងត្រូវ ជ្រើសរើសឈ្មោះតំណាងមួយគឺ Structure ដែលមានតួនាទីរក្សាទុកនូវក្រុមនៃប្រភេទទិន្ន័យដែលមានប្រភេទខុសៗគ្នាបាន​ ដែលមានឈ្មោះតែមួយ។ ឧទាហរណ៍: អ្នកចង់រក្សាទុកព័ត៌មានអំពីមនុស្សអំពីឈ្មោះរបស់គាត់ របស់នាង ចំនួនពលរដ្ឋ និងប្រាក់ខែ។ អ្នកអាចបង្កើតព័ត៌មានទាំងនេះ ដាច់ ដោយឡែក ប៉ុន្តែវិធីសាស្រ្តល្អប្រសើរជាងមុននឹងមានការប្រមូលព័ត៌មានទាំងនេះនៅក្រោមឈ្មោះតែមួយដោយសារតែព័ត៌មានទាំងអស់នេះគឺត្រូវបានទាក់ទងទៅនឹងមនុស្ ស។

Structure ទម្រងនៃការបង្កើត Structure 1.1 Structure គ្មាន Variable Syntax struct structure_name { data_type member1; data_type member2; . data_type memeber; };

Structure បរិយាយ ​​​​​​​​ struct:​ គឺជា keyword ដែលប្រើសំរាប់បង្កើត Structure។ ​​ struct_name​: ជាឈ្មោះរបស់ Structure។ datatype member:​ គឺជាការបង្កើត​ Variable នៅក្នុង struct

Structure ​​​​ ​ឩទាហណ៍ struct person { int​​ person_no; char name[50]; float salary; };

Structure 1.2 ការបង្កើត Variable នៅក្នុង Structure Syntax: struct structure_name variable1,variable2,…..,variable n; ឩទាហណ៍ៈ struct person { int​​ person_no; char name[50]; float salary; } p1 ,p2 ,p[20]; p1, p2, p[20] : មានន័យថា​ ការប្រកាស​ Variable ដែលបាន Instant(បង្កើត) នៅក្នុង ​​sruct រួចជាស្រេចដោយមិនចាំបាច់ instant នៅក្នុង main()​​ function​ ទេ។

Structure ទាញយក member នៅក្នុង Structure​​ មកបង្កើតក្នុង main() មុននឹងយើងអាចយក member នៅក្នុង struct មកប្រើប្រាស់ក្នុង​ main() Function បានត្រូវបង្កើត Object ជាមុនសិន។​ ដូ​ចនេះ​ Object ជា​ variable ដែលមានប្រភេទទិន្នន័យជា struct ឬក៏អាចនិយាយបានថា object គឺជាការលើកយក struct មកអនុវត្តន៏ដោយឈ្មោះតំនាងណាមួ យ។ ដើម្បីប្រើប្រាស់ member​ នៅក្នុង struct​ បានត្រូវតែ ប្រើ(access by)​សញ្ញា(.)​ ដើម្បីទាញ member(variable) ពី struct​ បា ន។​ ហើយត្រូវយកឈ្មោះ keyword struct ភ្ជាប់ជាមួយនឹង​ ឈ្មោះ stuct_name មកបង្កើតក្នុង main()​ function ដូចឩទាហណ៍នៅ slide បន្ទា ប់។

Structure ការប្រើប្រាស់ Structure ដោយគ្មាន Variable នៃ struct ការបង្កើត Object តាបរយៈ struct ការប្រើប្រាស់ member របស់ Struct

ការប្រើប្រាស់ Variableរបស់ Struct Structure ការប្រើប្រាស់ Structure ដែលមាន​​ Variable នៃ struct ការប្រើប្រាស់ Variableរបស់ Struct

ការទាញយក member មកពី​ Struct Employee Structure ការបង្កើត structure នៅក្នុង Structure ការបង្កើតបែបនេះក្នុងគោលបំណង ឱ្យstruct​ទាំងពីរមានទំនាក់ទំនងគ្នាដើម្បីទាញយក member ពី​ structure​ ណាមួយដែលមាន Object របស់ Structureនោះ។ Separate Structure ការទាញយក member មកពី​ Struct Employee

Structure Embeded Structure

Structure ការប្រើប្រាស់ structure និង pointer #include <stdio.h> struct name { int a; float b; }; void main() { struct name *ptr,p; ptr=&p; /* Referencing pointer to memory address of p */ printf("Enter integer: "); scanf("%d",&(*ptr).a); printf("Enter number: "); scanf("%f",&(*ptr).b); printf("Displaying: "); printf("%d%f",(*ptr).a,(*ptr).b); return 0; }

Structure

Structure

សំនួរ?