Structures

2,455 views

Published on

2 Comments
1 Like
Statistics
Notes
  • @kamleshdudve आपका समय देने के लिए बहुत-बहुत धन्यवाद, इस तरह का कमेन्ट में पहली बार नहीं सुन रहा हूँ, आपसे पहले भी कई लोग मुझसे यही कह चुके हैं पर मेरी समस्या यह है कि मैं इससे होने वाली आमदनी से अपने गांव में शिक्षा देने का काम करता हूँ, अगर इसको रोक दूँगा तो मुझे अपने गांव में बच्चों कों पढाने का काम छोडना होगा|

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

    फिर भी हम एक स्कीम चलाते हैं, आप हमारी 5000/- रु. की सेल करवाइए और हम आपको एक प्रोडक्ट फ्री में दे देंगे| मुझे उम्मीद है कि आपको मेरी बात बुरी नहीं लगी होगी- धन्यवाद |
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • 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.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,455
On SlideShare
0
From Embeds
0
Number of Embeds
195
Actions
Shares
0
Downloads
244
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Structures

  1. 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  2. 2. 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
  3. 3. 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
  4. 4. Structure… • Point is a combination of two cordinate. – (x , y) • Rectangle is a pair of points. – (x1, y1, x2, y2) 4
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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

×