logo

C의 구조 포인터

구조 포인터는 데이터를 저장하는 메모리 블록의 주소를 가리키는 포인터로 정의됩니다. 구조 구조 포인터로 알려져 있습니다. 연결된 목록, 트리, 그래프 등과 같은 복잡한 데이터 구조는 구조 포인터의 도움으로 생성됩니다. 구조 포인터는 변수를 구조 변수로 가리켜 메모리에 있는 구조의 주소를 알려줍니다.
예:




리눅스에서 내보내기 란 무엇입니까?





// C program to demonstrate structure pointer> #include> struct> point {> >int> value;> };> int> main()> {> >struct> point s;> > >// Initialization of the structure pointer> >struct> point* ptr = &s;> >return> 0;> }>



>

C# 스위치

>

위의 코드에서 에스 구조체 포인트의 인스턴스이고 ptr 구조체 포인트의 주소를 저장하기 때문에 구조체 포인터입니다.

포인터를 사용하여 구조체 멤버에 액세스

구조체 포인터를 사용하여 구조체 멤버에 액세스하는 방법에는 두 가지가 있습니다.

  1. (*) 별표 또는 간접 연산자와 (.) 점 연산자를 사용합니다.
  2. ( -> ) 화살표 연산자를 사용합니다.

다음은 도트 연산자의 도움으로 구조 포인터를 사용하여 구조 멤버에 액세스하는 프로그램입니다.


자바 배열에 추가하기



// C Program to demonstrate Structure pointer> #include> #include> struct> Student {> >int> roll_no;> >char> name[30];> >char> branch[40];> >int> batch;> };> int> main()> {> >struct> Student s1;> >struct> Student* ptr = &s1;> >s1.roll_no = 27;> >strcpy>(s1.name,>'Kamlesh Joshi'>);> >strcpy>(s1.branch,>'Computer Science And Engineering'>);> >s1.batch = 2019;> >printf>(>'Roll Number: %d '>, (*ptr).roll_no);> >printf>(>'Name: %s '>, (*ptr).name);> >printf>(>'Branch: %s '>, (*ptr).branch);> >printf>(>'Batch: %d'>, (*ptr).batch);> >return> 0;> }>

>

>

755 chmod
산출:

1>

다음은 화살표 연산자의 도움으로 구조 포인터를 사용하여 구조 멤버에 액세스하는 프로그램입니다. 이 프로그램에서는 구조 변수 s를 포함하는 Structure Student를 만들었습니다. Structure Student에는 Roll_no, 이름, 지점 및 배치가 있습니다.




// C Program to demonstrate Structure pointer> #include> #include> // Creating Structure Student> struct> Student {> >int> roll_no;> >char> name[30];> >char> branch[40];> >int> batch;> };> // variable of structure with pointer defined> struct> Student s, *ptr;> int> main()> {> >ptr = &s;> >// Taking inputs> >printf>(>'Enter the Roll Number of Student '>);> >scanf>(>'%d'>, &ptr->Roll_no);> >printf>(>'Enter Name of Student '>);> >scanf>(>'%s'>, &ptr->이름);> >printf>(>'Enter Branch of Student '>);> >scanf>(>'%s'>, &ptr->지점);> >printf>(>'Enter batch of Student '>);> >scanf>(>'%d'>, &ptr->배치);> >// Displaying details of the student> >printf>(>' Student details are: '>);> >printf>(>'Roll No: %d '>, ptr->Roll_no);> >printf>(>'Name: %s '>, ptr->이름);> >printf>(>'Branch: %s '>, ptr->지점);> >printf>(>'Batch: %d '>, ptr->배치);> >return> 0;> }>

img CSS 정렬

>

>

산출:

Enter the Roll Number of Student 27 Enter Name of Student Kamlesh_Joshi Enter Branch of Student Computer_Science_And_Engineering Enter batch of Student 2019 Student details are: Roll No: 27 Name: Kamlesh_Joshi Branch: Computer_Science_And_Engineering Batch: 2019>