Computer Programming Learning Part-05||Week-05||Declaring arrays with C++ programs with examples.

in Steem4Professionals16 days ago

Steemian Friends,
Today, I will write Computer Programming Learning Part-05 and show an example of declaring an array in a C++ program. I've been working on small programs and gradually getting closer to projecting through larger programs. Hopefully, everyone will benefit from reading my writing.

Programming Learning Part 05.png
Design By Canva

C++ Programming Array:
The same type of data is arranged and stored in computer memory in a C programming array. Today, we will make a small program to store some data, such as integers or floating-point numbers, in memory with a C++ program.

The array declaration rules are:

Data Type Array_Name [Array Size];

Here, data type means integer, character, or floating data. Type the data we will be processing. Then, the Array name has to be declared with any one character. Then, the Array size has to be given inside the fourth bracket. As many numbers as we give will be stored in memory. Below, I have declared an Array.

int a[4];

Here, the integer data type is int. The array name with a and four integer numbers inside the fourth bracket with 4 is indicated in memory.

I have shown below how to declare an Array in a C++ program with an example.

Step 01:

I first wrote a C++ program to declare an Array of four integer numbers on a white paper. Then, I wrote the program in the compiler called Code Blocks on the computer and saw the output.

IMG20240606103201.jpg

IMG20240606103414.jpg

Step 02:

Then I open the computer's Code Blocks software. Then I click on File. Click on New from File. Then click on Empty File and open a new C++ program page. I have shown it as a red block in the picture below.

1.png

2.png

3.png

Step 03:

I first declare the Header file and main function of the C++ program. Every C++ program has to do these two things at the beginning. I have written it below.

#include<stdio.h>
int main()
{}

Step 04:

Then, I will declare the Array of the C++ program. Today, I will show you how to declare an Array with integer numbers. Below, I have declared an Array with integer numbers.

int a[4];

Here, four integer types of data are declared to be stored in memory.

Step 05:

Now, I will pass four integer numbers to the computer through variables. The array variable number starts from 0, so I declared the first Array variable a[0]=1; the latter are declared as a[1], a[2], and a[3], respectively. I have written it below.

a[0]=1;
a[1]=2;
a[2]=4;
a[3]=50;

Step 06:

Then, I will write a C++ program to add three data from the declared data. I have written it below.

int x= a[0]+a[1]+a[2];

Step 07:

Then, I will write a C++ program to view the output, which is written to view the output of C++. Then, I return to close the program; I will end the program with.

printf ("%d\n",x);
return0;

Step 08:

Then, I completed the whole program and re-read it to make sure there were no mistakes. I have shown the entire program in the image below.


6.png

7.png

Step 09:

Then, I clicked on the Run button to run the program. The program I wrote didn't show any errors. After writing a program, it shows minor errors. But my program didn't error, so the direct output shows a black page. I declared three numbers, 1, 2, and 4, respectively, so the sum showed 7 as output. Below is the output of my written program.

output.png

Blue line.png

Link to my previous post:

Part-01

Part-02

Part-03

Part-04

Blue line.png

Steemit.com.png

image.png

Sort:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

STEEM DREAM TEAM

Your post has been successfully curated by our team via @𝐢𝐫𝐚𝐰𝐚𝐧𝐝𝐞𝐝𝐲 at 55%.

Thank you for your committed efforts, we urge you to do more and keep posting high-quality content for a chance to earn valuable upvotes from our team of curators and why not be selected for an additional upvote later this week in our top selection.



 16 days ago 

Thank You Dear Sir....

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.028
BTC 64467.84
ETH 3492.64
USDT 1.00
SBD 2.54