I don't understand a couple of things : Can you please explain some of these to me?


System ("cls")

//I know that it cleans, and it's used in Windows, but what exactly does it do, and what library should be included for it, if any?

//RELATED: System ("Pause" )
If I have a system ("cls") do I NEED to have the pause? What does that do? How should they be included?

static_cast <unsigned int> ( time ( NULL ) )

//I don't understand this line AT ALL

srand

// is this a predefined function?? I researched, and this is something I found: http://www.cplusplus.com/reference/cstdlib/srand/ ... but I need a little more help with the function. How exactly does it work?

RELATED: //Also, with rand (), is it the same thing just that it returns the same number...? I'm really confused.

enum

// This was never used again in the program, and I don't really know what it's for. Just that it's a global variable...

a &= 0x5F

// Is this just a number, then why have a & operator?


Last edited on
typedef:
Those who use typedef use it to simplify things.
Imagine a declaration of the type:
unsigned long long int my_var;
Now imagine you have to declare many such variables, that's a lot of typing.
Now, consider:
typedef unsigned long long int ulli;
You can now re-write the above declaration and similar ones as :
ulli my_var;
Imagine this:
prototype:
void my_func(int * ((*)(const char *)));
definition:
1
2
3
4
void my_func(int * ((*func)(const char *)))
{
	int x = *(func("hello"));
}

a function whose sole parameter is a pointer to a function that returns a pointer to an int and whose sole parameter is null terminated string.
Easy to get wrong, especially if we use this same type multiple times. However with:
typedef int * ((* mfnp)(const char *));
We can simply say
1
2
3
4
5
void my_func(mfnp);
void my_func(mfnp func)
{
	int x = *(func("hello"));
}

Saves you a lot of typing, I do not say whether it is good or bad.
system("");
This is a way of running an operating system command from within your program. It is as though you temporarily leave your program and run the command within the quotes on the command line. You can put any of your usual shell commands here.
On Windows you can say system("dir"); on linux system("ls"); This is generally a bad idea, and is used by people who are in a hurry or just don't care. It makes too many assumptions about the operating environment.
system("cls"); for example will not work on Linux, and may delete your files on some other operating systems.
There is no direct connection (except the programmer) between system("cls"); and system("pause") - again system("pause") is just issuing the "pause" command at the command line. "pause" will freeze the screen and wait for you to press any key before continuing. So, people use it to keep their program window from closing down automatically when their program ends.
I beg you to avoid system("") anything, I think looking for alternatives will help you more than you know.
static_cast <unsigned int> ( time ( NULL ) )
This is calling the standard library function time(), with an argument of NULL, and casting the return value to an unsigned int. time() returns the current time of day.
srand() is another standard library function, that seeds the random number generator. People tend to use this with the return value of time(), in an effort to seed the generator with an unpredicatable value.
rand() is yet another standard library function that actually generates a random number (well, pseudo-random)
enum is a keyword used to create enumerations. You would use the created enumeration later in the program, not necessarily repeating the enum keyword itself.
a &= 0x5f
& is the symbol for bitwise AND, in this case, the individual bits of the value in ariable a will be ANDed with the corresponding bits of the hexadecimal number 0x5F, and the result will be stored in a. What you're seeing here is probably an example of bit masking, ensuring that the bit 5 of a gets cleared, while bits 0 to 4 and 6 remain undisturbed. All higher order bits will be cleared.
time.h
You must have seen something like
#include <time.h>
This is how headers are included in the code.
array[i][j].val
This gets the object in the ith row and jth column of this array. This object is a composite type, and the dot operator is how members of the type are selected. Imagine:
1
2
3
4
5
6
7
8
9
10
typedef struct
{
	int x;
	int y;
}  Point;

Point pointsArray[10];
...
pointsArray[i].x = 0;
pointsArray[i].y = 2;

Finally:
Yes, providing the code is better and would get you better, possibly correct answers. Except in this case, because RTFM
Topic archived. No new replies allowed.