SlideShare a Scribd company logo
structure,pointerandstring
ReshmaRaju
chippykutty5593@gmail.com
chippykutty5593@gmail.com
twitter.com/username
in.linkedin.com/in/profilename
8547829221
STRUCTURE, POINTER AND STRING
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
STRUCTURE
• Structure is a collection of different data type which are
grouped and each element in c structure is called members.
• Structure help to construct a complex data type in more
meaningful.
• It is similar to an array. The only difference is that array is
used to store collection of similar data type, but structure can
store collection of any type of data.
Syntax of structure
struct structure_name
{
data_type member1;
data_type member2;
.
.
data_type memeber;
};
Example for structure
#include <stdio.h>
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
struct student s;
printf("Enter information of students:nn");
printf("Enter name: ");
scanf("%s",s.name);
printf("Enter roll number: ");
scanf("%d",&s.roll);
printf("Enter marks: ");
scanf("%f",&s.marks);
printf("nDisplaying Informationn");
printf("Name: %sn",s.name);
printf("Roll: %dn",s.roll);
printf("Marks: %.2fn",s.marks);
return 0;
}
OUTPUT
Enter information of students:
Enter name: Anu
Enter roll number: 1
Enter marks: 852
Displaying Information
Name: Anu
Roll: 1
Marks: 852
POINTER
• Pointer is a user defined data type which creates special types
of variables which can hold the address of primitive data type
like char, int, float, double or user defined data type like
function, pointer etc. or derived data type like array, structure
etc.
• The general form of a pointer variable declaration is:
type *var-name;
NULL POINTER
• It is always a good practice to assign a NULL value to a
pointer variable in case you do not have exact address to be
assigned. This is done at the time of variable declaration.
• A pointer that is assigned NULL is called a null pointer.
• The NULL pointer is a constant with a value of zero defined in
several standard libraries
Example for pointer
#include <stdio.h>
int main ()
{
int var = 20; // actual variable declaration
int *ip; // pointer variable declaration
ip = &var; // store address of var in pointer variable
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip ); // address stored in pointer variable
printf("Value of *ip variable: %dn", *ip ); // access the value using the pointer
return 0;
}
OUTPUT
Address of var variable: 28ff18
Address stored in ip variable: 28ff18
Value of *ip variable: 20
STRING
• The string in C programming language is actually a one-
dimensional array of characters which is terminated by
a null character '0'.
• Thus a null-terminated string contains the characters that
comprise the string followed by a null.
• The length of the string is the number of character + one
( null character )
Functions & purpose of string
S.N
.
Function & Purpose
1 strcpy(s1, s2);
Copies string s2 into string s1.
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.
5 strchr(s1, ch);
Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);
Returns a pointer to the first occurrence of string s2 in string s1.
Example for string
#include <stdio.h> OUTPUT
#include <string.h> strcpy( str3, str1) : Hello
int main () strcat( str1, str2): HelloWorld
{ strlen(str1) : 10
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12];
int len ;
strcpy(str3, str1); // copy str1 into str3
printf("strcpy( str3, str1) : %sn", str3 );
strcat( str1, str2); // concatenates str1 and str2
printf("strcat( str1, str2): %sn", str1 );
len = strlen(str1); // total lenghth of str1 after concatenation
printf("strlen(str1) : %dn", len );
return 0;
}
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

PDF
Data structure week 2
PDF
Data structure week 3
PPT
Structures
PPTX
Dynamic memory allocation in c++
PPT
Strings
PPT
Strings
PPTX
This pointer
PPTX
Structure & union
Data structure week 2
Data structure week 3
Structures
Dynamic memory allocation in c++
Strings
Strings
This pointer
Structure & union

What's hot (20)

PPTX
Pointers in c++
PPTX
Pointer in C
PPTX
Pointers in c++
PPTX
Template C++ OOP
PPTX
Pointer and polymorphism
PPTX
Templates in C++
PPTX
Pointer in C++
PPTX
Pointers in C/C++ Programming
PDF
C Pointers
PPTX
ppt on pointers
PPT
Pointer in C
PPTX
Pointers
PPTX
Used of Pointer in C++ Programming
PPTX
Presentation on pointer.
PPTX
Pointer in c program
DOCX
C++ Template
PDF
Lk module5 pointers
PPTX
Dynamic Memory allocation
PPTX
c++ pointers by Amir Hamza Khan (SZABISTIAN)
PDF
Pointers & References in C++
Pointers in c++
Pointer in C
Pointers in c++
Template C++ OOP
Pointer and polymorphism
Templates in C++
Pointer in C++
Pointers in C/C++ Programming
C Pointers
ppt on pointers
Pointer in C
Pointers
Used of Pointer in C++ Programming
Presentation on pointer.
Pointer in c program
C++ Template
Lk module5 pointers
Dynamic Memory allocation
c++ pointers by Amir Hamza Khan (SZABISTIAN)
Pointers & References in C++
Ad

Viewers also liked (6)

PPTX
Mca ii dfs u-2 array records and pointer
PDF
PPTX
PPTX
PPT
Unit 6 pointers
Mca ii dfs u-2 array records and pointer
Unit 6 pointers
Ad

Similar to structure,pointerandstring (20)

PPTX
Pointers and Dynamic Memory Allocation
PPTX
introduction to strings in c programming
PDF
Principals of Programming in CModule -5.pdf
DOCX
string , pointer
PPTX
C Programming Unit-4
PPTX
Unit-4-1.pptxjtjrjfjfjfjfjfjfjfjrjrjrjrjejejeje
PPTX
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
PPTX
Pointers in C Language
PPT
structures.ppt
PPT
Introduction to structures in c lang.ppt
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
PPT
Unit4 C
PDF
Principals of Programming in CModule -5.pdfModule-4.pdf
PPTX
C programming(part 3)
PPTX
Algoritmos e Estruturas de Dados - Pointers
DOC
Assignment c programming
PPTX
Lecture_on_string_manipulation_functions.pptx
PPTX
PDF
Pointers are one of the core components of the C programming language.
PPTX
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8
Pointers and Dynamic Memory Allocation
introduction to strings in c programming
Principals of Programming in CModule -5.pdf
string , pointer
C Programming Unit-4
Unit-4-1.pptxjtjrjfjfjfjfjfjfjfjrjrjrjrjejejeje
ECE2102-Week13 - 14-Strhhhhhhhjjjucts.pptx
Pointers in C Language
structures.ppt
Introduction to structures in c lang.ppt
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Unit4 C
Principals of Programming in CModule -5.pdfModule-4.pdf
C programming(part 3)
Algoritmos e Estruturas de Dados - Pointers
Assignment c programming
Lecture_on_string_manipulation_functions.pptx
Pointers are one of the core components of the C programming language.
Lecture 24 PART 1.pptxkhfwraetrsytfyugiuihjojiiyutdruot8

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

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

structure,pointerandstring

  • 3. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. STRUCTURE • Structure is a collection of different data type which are grouped and each element in c structure is called members. • Structure help to construct a complex data type in more meaningful. • It is similar to an array. The only difference is that array is used to store collection of similar data type, but structure can store collection of any type of data.
  • 5. Syntax of structure struct structure_name { data_type member1; data_type member2; . . data_type memeber; };
  • 6. Example for structure #include <stdio.h> struct student { char name[50]; int roll; float marks; }; int main() { struct student s; printf("Enter information of students:nn"); printf("Enter name: "); scanf("%s",s.name); printf("Enter roll number: "); scanf("%d",&s.roll); printf("Enter marks: "); scanf("%f",&s.marks);
  • 7. printf("nDisplaying Informationn"); printf("Name: %sn",s.name); printf("Roll: %dn",s.roll); printf("Marks: %.2fn",s.marks); return 0; } OUTPUT Enter information of students: Enter name: Anu Enter roll number: 1 Enter marks: 852 Displaying Information Name: Anu Roll: 1 Marks: 852
  • 8. POINTER • Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data type like char, int, float, double or user defined data type like function, pointer etc. or derived data type like array, structure etc. • The general form of a pointer variable declaration is: type *var-name;
  • 9. NULL POINTER • It is always a good practice to assign a NULL value to a pointer variable in case you do not have exact address to be assigned. This is done at the time of variable declaration. • A pointer that is assigned NULL is called a null pointer. • The NULL pointer is a constant with a value of zero defined in several standard libraries
  • 10. Example for pointer #include <stdio.h> int main () { int var = 20; // actual variable declaration int *ip; // pointer variable declaration ip = &var; // store address of var in pointer variable printf("Address of var variable: %xn", &var ); printf("Address stored in ip variable: %xn", ip ); // address stored in pointer variable printf("Value of *ip variable: %dn", *ip ); // access the value using the pointer return 0; } OUTPUT Address of var variable: 28ff18 Address stored in ip variable: 28ff18 Value of *ip variable: 20
  • 11. STRING • The string in C programming language is actually a one- dimensional array of characters which is terminated by a null character '0'. • Thus a null-terminated string contains the characters that comprise the string followed by a null. • The length of the string is the number of character + one ( null character )
  • 12. Functions & purpose of string S.N . Function & Purpose 1 strcpy(s1, s2); Copies string s2 into string s1. 2 strcat(s1, s2); Concatenates string s2 onto the end of string s1. 3 strlen(s1); Returns the length of string s1. 4 strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2. 5 strchr(s1, ch); Returns a pointer to the first occurrence of character ch in string s1. 6 strstr(s1, s2); Returns a pointer to the first occurrence of string s2 in string s1.
  • 13. Example for string #include <stdio.h> OUTPUT #include <string.h> strcpy( str3, str1) : Hello int main () strcat( str1, str2): HelloWorld { strlen(str1) : 10 char str1[12] = "Hello"; char str2[12] = "World"; char str3[12]; int len ; strcpy(str3, str1); // copy str1 into str3 printf("strcpy( str3, str1) : %sn", str3 ); strcat( str1, str2); // concatenates str1 and str2 printf("strcat( str1, str2): %sn", str1 ); len = strlen(str1); // total lenghth of str1 after concatenation printf("strlen(str1) : %dn", len ); return 0; }
  • 15. 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.
  • 16. 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
  • 17. 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