SlideShare a Scribd company logo
1 of 21
STRUCTURE, POINTER, STRING
NikhilDevS.B
nikhildevsb@gmail.com
www.facebook.com/nikhildevsb
TwitterProfile
www.linkedin.com/nikhildevsb
Disclaimer: This presentation is prepared by trainees of
baabtra.com as a part of mentoring program. This is not
official document of baabtra.com – Mentoring Partner
OVER VIEW
1.STRUCTURES
2.POINTERS
3.STRING
STRUCTURES
Collection of data items of different types using a single name,
user defined datatype.
Grouping several pieces of related information together, array can
store only single type data.
E.g1. It can handle student_name,roll_number and marks under a
single name student.
E.g2. book: author ,price ,year.
 customer: name, telephone, city, category.
DEFINING A STRUCTURE
struct tag-name
{
datatype member1;
datatype member2;
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
};
E.g. struct book_bank
{
char title[20];
char author[15];
int pages;
float price;
};
DEFINING STRUCTURE TYPE
VARIABLE• Declare a variable of type structure to access the
members of structure.
• struct book_bank
{
char title[20];
char author[15];
int pages;
float price;
};
struct book_bank book1,book2,book3;
• arrays of strucctures: struct book_bank book[3];
Another type of declaration:
• struct book_bank
{
char title[20];
char author[15];
int pages;
float price;
} book1,book2,book3;
ACCESSING STRUCTURE MEMBERS
• We access and assign values to structure members.
• Access can be done by member operator ‘ . ’ also
known as dot operator period operator or by ->
(pointer to structure)
•E.g. book1.price=250;
book1.pages=300;
scanf(“%s”,book.title);
STRUCTURE INITIALIZATION
• struct
{
int weight;
float height;
} student ={60,180.75};
• struct st_record
{
int weight;
float height;
} ;
struct st_record student1={60,180.75};
POINTERS
• Derived data type in C.
• Contain memory address as their values. i.e. It
stores memory address of another variable.
• Pointers reduce length of program.
• Declare as int *ptr
• Initialize pointer as null int *ptr=0 or int *ptr=NULL
& (address operator)
Returns address of operand
int y = 5;
int *yPtr;
yPtr = &y; //yPtr gets address of y
yPtr “points to” y
yPtr
y
5
yptr
500000 600000
y
600000 5
Address of y
is value of
yptr
• Declare an array int b[5] and a pointer int * bPtr
bPtr = b;
Array name actually a address of first element
OR
bPtr = &b[0].
C uses two pointer operators,
Indirection operator (*) – to get the value belongs to the address.
Address-of-operator (&) – ampersand symbol, means return the
address of a variable.
When & operator is placed before the name of a variable, it will
returns the memory address of the variable instead of stored
value.
#include<stdio.h>
#include<conio.h>
void main()
{
int x,*p,y;
x=10;
p=&x;
y=*p; // accessing x through p OUTPUT
*p=20; // assigning 20 to x P: 2686734 (Address of x)
printf("ntp:%d",p); *p: 20
printf("nt*p:%d",*p); y: 10
printf("nty:%d",y);
getch();
}
STRING
• Sequence of characters treated as single data item
• There is no string type, we implement strings as arrays of
characters in C.
• E.g. “Welcome”;
DECLARE A STRING
• char str[10]; // str is an array of 10 chars or a string
• char str[10]=“Welcome” // Declare and initialize a string.
• char str[10]= { ‘w’, ’e’ , ’l’ , ‘c’ , ‘o’ , ‘m’ , ‘e’ }
READING A STRING
• scanf(“%s”,str); // read a string, no need of &
sign.
• gets(str); // read a string with white
spaces.
• scanf(“%5s”, str); // read only five characters even
str can hold 10.
• for(i=0;i<10;i++)
{
scanf(“%c”,&str[i]) // read by character-by character;
}
Writing string to screen
• printf(“%s”, str);
• puts(str);
STRING FUNCTION
• strcpy(s1, s2) – copies s2 into s1 (including ‘0’ as last char)
• strncpy(s1, s2, n) – same but only copies up to n chars of s2
• strcmp(s1, s2) – returns a negative int if s1 < s2, 0 if s1 = = s2 and a
positive int if s1 > s2
• strcat(s1, s2) – concatenates s2 onto s1 (this changes s1, but not s2)
• strlen(s1) – returns the integer length of s1
Thank you...
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

More Related Content

What's hot (20)

C Pointers
C PointersC Pointers
C Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
pointers
pointerspointers
pointers
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Presentation
PresentationPresentation
Presentation
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Learn Function The Hard Way
Learn Function The Hard WayLearn Function The Hard Way
Learn Function The Hard Way
 
Pointers - DataStructures
Pointers - DataStructuresPointers - DataStructures
Pointers - DataStructures
 
Pointer
PointerPointer
Pointer
 
Roadmap to Object Oriented Programming
Roadmap to Object Oriented ProgrammingRoadmap to Object Oriented Programming
Roadmap to Object Oriented Programming
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
Pointers
PointersPointers
Pointers
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 
Pointers
PointersPointers
Pointers
 
String searching
String searchingString searching
String searching
 

Viewers also liked

Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 

Viewers also liked (20)

Strings and pointers
Strings and pointersStrings and pointers
Strings and pointers
 
Oops
OopsOops
Oops
 
Baabtra.com little coder chapter - 4
Baabtra.com little coder   chapter - 4Baabtra.com little coder   chapter - 4
Baabtra.com little coder chapter - 4
 
Hiring in startups - What you should know.
Hiring in startups - What you should know. Hiring in startups - What you should know.
Hiring in startups - What you should know.
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Inheritance
InheritanceInheritance
Inheritance
 
Transaction
TransactionTransaction
Transaction
 
Jquery
JqueryJquery
Jquery
 
Code optimization
Code optimization Code optimization
Code optimization
 
Baabtra.com little coder chapter - 6
Baabtra.com little coder   chapter - 6Baabtra.com little coder   chapter - 6
Baabtra.com little coder chapter - 6
 
Oop cocepts
Oop coceptsOop cocepts
Oop cocepts
 
Baabtra.com little coder chapter - 3
Baabtra.com little coder   chapter - 3Baabtra.com little coder   chapter - 3
Baabtra.com little coder chapter - 3
 
Database and types of database
Database and types of databaseDatabase and types of database
Database and types of database
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
What is Android
What is AndroidWhat is Android
What is Android
 
Introduction to mysql part 2
Introduction to mysql part 2Introduction to mysql part 2
Introduction to mysql part 2
 
Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 

Similar to Strctures,strings,pointers

Similar to Strctures,strings,pointers (20)

structure,pointerandstring
structure,pointerandstringstructure,pointerandstring
structure,pointerandstring
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Overloading
OverloadingOverloading
Overloading
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Lecture5
Lecture5Lecture5
Lecture5
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
C++_notes.pdf
C++_notes.pdfC++_notes.pdf
C++_notes.pdf
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
Pointers
PointersPointers
Pointers
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 

Strctures,strings,pointers

  • 1.
  • 3. Disclaimer: This presentation is prepared by trainees of baabtra.com as a part of mentoring program. This is not official document of baabtra.com – Mentoring Partner
  • 5. STRUCTURES Collection of data items of different types using a single name, user defined datatype. Grouping several pieces of related information together, array can store only single type data. E.g1. It can handle student_name,roll_number and marks under a single name student. E.g2. book: author ,price ,year.  customer: name, telephone, city, category.
  • 6. DEFINING A STRUCTURE struct tag-name { datatype member1; datatype member2; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . }; E.g. struct book_bank { char title[20]; char author[15]; int pages; float price; };
  • 7. DEFINING STRUCTURE TYPE VARIABLE• Declare a variable of type structure to access the members of structure. • struct book_bank { char title[20]; char author[15]; int pages; float price; }; struct book_bank book1,book2,book3; • arrays of strucctures: struct book_bank book[3];
  • 8. Another type of declaration: • struct book_bank { char title[20]; char author[15]; int pages; float price; } book1,book2,book3;
  • 9. ACCESSING STRUCTURE MEMBERS • We access and assign values to structure members. • Access can be done by member operator ‘ . ’ also known as dot operator period operator or by -> (pointer to structure) •E.g. book1.price=250; book1.pages=300; scanf(“%s”,book.title);
  • 10. STRUCTURE INITIALIZATION • struct { int weight; float height; } student ={60,180.75}; • struct st_record { int weight; float height; } ; struct st_record student1={60,180.75};
  • 11. POINTERS • Derived data type in C. • Contain memory address as their values. i.e. It stores memory address of another variable. • Pointers reduce length of program. • Declare as int *ptr • Initialize pointer as null int *ptr=0 or int *ptr=NULL
  • 12. & (address operator) Returns address of operand int y = 5; int *yPtr; yPtr = &y; //yPtr gets address of y yPtr “points to” y yPtr y 5 yptr 500000 600000 y 600000 5 Address of y is value of yptr
  • 13. • Declare an array int b[5] and a pointer int * bPtr bPtr = b; Array name actually a address of first element OR bPtr = &b[0]. C uses two pointer operators, Indirection operator (*) – to get the value belongs to the address. Address-of-operator (&) – ampersand symbol, means return the address of a variable. When & operator is placed before the name of a variable, it will returns the memory address of the variable instead of stored value.
  • 14. #include<stdio.h> #include<conio.h> void main() { int x,*p,y; x=10; p=&x; y=*p; // accessing x through p OUTPUT *p=20; // assigning 20 to x P: 2686734 (Address of x) printf("ntp:%d",p); *p: 20 printf("nt*p:%d",*p); y: 10 printf("nty:%d",y); getch(); }
  • 15. STRING • Sequence of characters treated as single data item • There is no string type, we implement strings as arrays of characters in C. • E.g. “Welcome”; DECLARE A STRING • char str[10]; // str is an array of 10 chars or a string • char str[10]=“Welcome” // Declare and initialize a string. • char str[10]= { ‘w’, ’e’ , ’l’ , ‘c’ , ‘o’ , ‘m’ , ‘e’ }
  • 16. READING A STRING • scanf(“%s”,str); // read a string, no need of & sign. • gets(str); // read a string with white spaces. • scanf(“%5s”, str); // read only five characters even str can hold 10. • for(i=0;i<10;i++) { scanf(“%c”,&str[i]) // read by character-by character; }
  • 17. Writing string to screen • printf(“%s”, str); • puts(str); STRING FUNCTION • strcpy(s1, s2) – copies s2 into s1 (including ‘0’ as last char) • strncpy(s1, s2, n) – same but only copies up to n chars of s2 • strcmp(s1, s2) – returns a negative int if s1 < s2, 0 if s1 = = s2 and a positive int if s1 > s2 • strcat(s1, s2) – concatenates s2 onto s1 (this changes s1, but not s2) • strlen(s1) – returns the integer length of s1
  • 19. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 20. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 21. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us