Computer Programming Learning Part-05||Week-05||Declaring arrays with C++ programs with examples.
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.
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.
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.
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.
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()
{}
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.
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;
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];
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;
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.
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.
Link to my previous post:
Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(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.
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1798653768206311869?t=c0BnNnEVYnVToNYR-2twQw&s=19
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.
Thank You Dear Sir....