[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Array and Structure DevC++

The document provides two examples of C++ code: one demonstrating the use of an array to store integers and another illustrating a structure to manage student data. Each example includes code snippets and mentions corresponding output screenshots. The array example initializes and prints five integers, while the structure example defines a student with attributes for name, age, and grade, and prints these details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Array and Structure DevC++

The document provides two examples of C++ code: one demonstrating the use of an array to store integers and another illustrating a structure to manage student data. Each example includes code snippets and mentions corresponding output screenshots. The array example initializes and prints five integers, while the structure example defines a student with attributes for name, age, and grade, and prints these details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Array and Structure in C++

This document contains two examples of C++ code: one for an array and one for a structure.
Below each code example, you will find the corresponding screenshot of the output
generated using Dev-C++.

Example 1: Array in C++

#include <iostream>
using namespace std;

int main() {
// Declare and initialize an array of 5 integers
int numbers[5] = {10, 20, 30, 40, 50};

// Print all elements in the array


cout << "Array elements are: ";
for(int i = 0; i < 5; i++) {
cout << numbers[i] << " ";
}

return 0;
}

Output:
Screenshot of the output will be here.

Example 2: Structure in C++

#include <iostream>
#include <cstring>
using namespace std;

// Define a structure to store student data


struct Student {
char name[50];
int age;
float grade;
};
int main() {
// Declare a structure variable
Student student1;

// Assign values to structure members


strcpy(student1.name, "John");
student1.age = 20;
student1.grade = 85.5;

// Print the student data


cout << "Student Name: " << student1.name << endl;
cout << "Student Age: " << student1.age << endl;
cout << "Student Grade: " << student1.grade << endl;

return 0;
}

Output:
Screenshot of the output will be here.

You might also like