Structures
Upcoming SlideShare
Loading in...5
×
 

Structures

on

  • 1,532 views

 

Statistics

Views

Total Views
1,532
Views on SlideShare
1,426
Embed Views
106

Actions

Likes
0
Downloads
102
Comments
2

3 Embeds 106

http://www.ustudy.in 81
http://en.learnbywatch.com 24
http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • @kamleshdudve आपका समय देने के लिए बहुत-बहुत धन्यवाद, इस तरह का कमेन्ट में पहली बार नहीं सुन रहा हूँ, आपसे पहले भी कई लोग मुझसे यही कह चुके हैं पर मेरी समस्या यह है कि मैं इससे होने वाली आमदनी से अपने गांव में शिक्षा देने का काम करता हूँ, अगर इसको रोक दूँगा तो मुझे अपने गांव में बच्चों कों पढाने का काम छोडना होगा|

    रही बात गरीबी की तो आप भी गरीब नहीं हैं, यदि गरीब होते तो सब्जी बेच रहे होते या रिक्शा चला रहे होते या ऐसा ही कुछ और कर रहे होते पर इंटरनेट का प्रयोग नहीं कर रहे होते, मैंने कई बार गरीबों कों पढाने की कोशिश की है पर वो कभी भी पढ़ने नही आये क्यूंकि यदि वो पढ़ने आयेंगे तो उतने समय की उनकी कमाई पर फर्क पड़ेगा जो उनके लिए बहुत नुकसान का सौदा होगा|

    फिर भी हम एक स्कीम चलाते हैं, आप हमारी 5000/- रु. की सेल करवाइए और हम आपको एक प्रोडक्ट फ्री में दे देंगे| मुझे उम्मीद है कि आपको मेरी बात बुरी नहीं लगी होगी- धन्यवाद |
    Are you sure you want to
    Your message goes here
    Processing…
  • sir ye free nhi ho sakta isse kai logo ka bhala hoga......
    ye baat alag he ki aap ki aamdani yhi se aati hogi but hindi me wahi log dhundte he jo garib hote he....
    so please sir audio slides availble kr do.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Structures Structures Presentation Transcript

    • C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
    • t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS STRUCTURES 2
    • Structure • Collection of one or more variable. • Can be of different data types. • Grouped together under a single name. • Example: – Student can be described as a set of attributes. • Name • Address • Roll no 3
    • Structure… • Point is a combination of two cordinate. – (x , y) • Rectangle is a pair of points. – (x1, y1, x2, y2) 4
    • Structure • Structure declaration struct point { int x; int y; }; – Use struct keyword to declare a structure. – point is the name of structure. – x and y are the member of the point structure. – Remember semi-colon after curly bracket. 5
    • Structure… • Structure member name can be same of: – Normal variable name in the program. – Member name in other structure. – Context is different. • Structure declaration defines a data type. • A structure declaration do not reserve storage. 6
    • Structure… • Structure can also be declared as:- struct point { int x; int y; } a, b, c; • a, b, c are the variables of point type. • These variables reserves memory space. 7
    • Structure… struct point a; • Defines a variable of point type. • Initialization: struct point a = {12, 14}; • Initialize x to 12 and y to 14. • Remember:- struct point a; a = {12,14}; 8
    • Structure… • You can also initialize each member separately as:- a.x = 12; a.y = 14; • You can access structure members by – Structure_name.member; scanf(“%d %d”, &a.x, &a.y); printf(“%d %d”, a.x, a.y); 9
    • Nested Structures • A rectangle can be declare as a pair of points. struct rect { struct point p1; struct point p2; }; • Here, rect structure contains two point structures. struct rect r1 = {12, 14, 15, 16}; printf(“%d %d”, r1.p1.x, r1.p1.y); 10
    • Mind Bend • Declare a structure named student with the following members:- – Name [char pointer], – address [char pointer], – roll_no [int]. • Define a variable s1 in main(). • Initialize all member and print them in main(). • You can also declare address as a separate structure. 11
    • Structures and Function • Pass structures to a function can be done by:- – Pass components separately. – Pass an entire structure. – Pass a pointer to a structure. 12
    • Pass Components Separately • To initialize a structure dynamically:- struct point makepoint (int x, int y) { struct point temp; temp.x = x; temp.y = y; return temp; } • Take 2 integers and return a point structure. 13
    • Pass Structure • Next we can pass structures to functions as:- struct point addpoint (struct point p1, struct point p2) { p1.x += p2.x; p1.y += p2.y; return p1; } • Return value and arguments are structures. 14
    • Pass Pointer to Structure • For a large structure it is more efficient to pass a pointer to structure. struct point *pp; • Define a pointer pp to a structure type point. struct point *pp, p1; pp = &p1; (*pp).x = 12; (*pp).y = 14; 15
    • Pass Pointer to Structure • Parantheses is required because preference of structure operator “.” Is higher than indiraction operator “*”. (*pp).y = 14; • *pp.y means *(pp.y) which is illegal because y is not a pointer. • Instead (*pp).y, pp->y can also be used. 16
    • typedef • Create new data type names. typedef int Length; • Create a new name (Length) for int. – typedef data_type new_name; • Length now can be used instead of int in declaration and casting. • Use typedef with Structures. 17
    • To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS UNIONS, BITWISE, BIT-FIELDS AND ENUM 18