C++ Learning Day 2

Variables

#‎include‬ <iostream>

int main()
{
std::cout << sizeof( int ) << std::endl;
std::cout << sizeof( float ) << std::endl;

}

Scope

#include <iostream>

int main()
{
i nt var1 = 0;
int var2 = 5;

{
int var3 = 7;
int var4 = var3 + var2;
}

int var5 = var2;
}

 

#include <iostream>

int main()
{
int num1 = 10;
int num2 = 4;

int num3 = num1 * num2;

std::cout << num1 << ” * ” << num2 << ” = ” << num3 << std::endl;
}

#include <iostream>

int main(int argc, char **argv)
{

int moreNumbers[ 3 ];
moreNumbers[ 0 ] = 68;
moreNumbers[ 1 ] = 37;
moreNumbers[ 2 ] = 76;

int evenMoreNumbers [ 5 ] = { 4, 7, 21, 78, 23 };
int severalNumber[] = { 23, 5, 23, 65, 12, 76, 34, 98, 123, 67, 12, 76 };

return 0;
}

#include <iostream>

int main()
{
int var = 0;
while ( var < 10 )
{
std::cout << “We are looping until var is 10. var is currently ” << var << “.” << std::endl;
++var;

}

std::cout << “We finished our loop, and var is now ” << var << “.” << std::endl;

}

#include <iostream>

int main()
{
int var = 0;
while ( var < 10 )
{
std::cout << “We are looping until var is 10. var is currently ” << var << “.” << std::endl;
++var;

}

std::cout << “We finished our loop, and var is now ” << var << “.” << std::endl;

}

#include <iostream>

int main()
{
for ( int i = 0; i < 10; ++i )
{
std::cout << “We are looping until i is 10, expect with a for statement this time. i is currently ” << i << “,” << std::endl;
}
std::cout << “We finished our loop!” << std::endl;

}

#include <iostream>

int main()
{
for ( int i = 90; i < 10; ++i )
{
std::cout << “Nooooooooooooooo, nothing. i is currently ” << i << “,” << std::endl;
}
std::cout << “Yessssssssss!” <<std::endl;

}

#include <iostream>

int main ()
{
int input;

std::cout << “Input an integer: “;
std::cin >> input;
std::cout << “Your number was: ” << input << std::endl;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s