Hey Everyone, I am Vikram Salunke and welcome to the x86 Assembly Course.
Now let's look at the second program Input and Output.

c programming input and output

This is a program for input and output.
Let's first run it and look at what is happening here.

First we need to put a breakpoint, so I will put a breakpoint here.

Then click on Build -> Build Solution. So, we have successfully compiled the program.

Now we need to run it. To run click on this play icon.

c programming input and output

It's asking enter your age. Let's type 20.

After that it's asking name let's enter my name Vikram.

The values which we have entered are outputted by the program. Age = 20 and name = vikram

To stop the execution of a program we need to click a stop icon here (stop debugging).

Now, let's look at what is this program doing.

The first line #include it is a preprocessor command which telling the C compiler to include stdio.h file before going to actual compilation

Next line is int main(){ main function where program execution begins and { telling the compiler that main() program's body has been started

Next is a int age; so what we are doing? we are defining age variable with int data type which we have seen earlier

Next is a char name[100]; so what we are doing? we are defining character array of a size 100 for variable name

What is a array that we will see in upcoming slides

Next we are using printf statement by asking for a age printing on a screen such as Enter your age.

Now we are using scanf function defined in stdio.h file

What we are doing?

We are getting the input from the user and storing it in age variable.

So we are using %d for int

Next we are asking for name by printing Enter your name on a screen

Then we are getting input from user and storing it in a name variable

we are using %s because the name is a string and we want to save it into character array that's why we are using %s

the next line is we are printing what user have entered onto the screen so we are using %d to print the integer and we will use %s to print the string on a screen.

and the next line is as usual return 0; that terminating the main() program's body.


So, now we will look at the Arrays

So array is a fixed-size sequential collection of elements of the same type

to define an array we write int num[6];

so six memory locations will be given to the variable num to save the six elements of a same data type

c programming arrays

another way we can write the array such as int num[] = {100,200,300,400,500,600};


so what is happening here, we are giving the six memory locations for the int num variable then on 0th location we will save the 100 on the 1st location we will save 200 then 300, 400, 500, 600 onto the 3rd, 4th and 5th location

remember this thing - array start with the 0 till the N-1

we also can access a single element from that array such as . a if we want to access just the 0th element of an array we can use num[0] if we want to access 1st element we can use num[1] and so on we can access every element of an array from 0 to 5.

If you want to join our in person class then please click here we are doing trainings in some upcoming InfoSec conferences.
And if you have any doubts, any questions then you can tweet me @vikramsalunke20
We are uploading daily new videos on YouTube click here to subscribe.
If you want to solve the exercises on this topic those are below. Solve the exercises and check your understandings. Thank you :)