Creating global and local objects

I'm having trouble remembering how to create global and local objects for an assignment I have to do. Can anyone give me an example how I should create a global object, global static object, local automatic object, and local static object. I mostly don't understand how to do something like this:




1
2
3
4
5
6
7
8
9
10
Write a test program that creates the following Account objects in order:
1.One global object before main with Account ID 1111, initial balance $1000
2.One static object before main with Account ID 2222, initial balance $2000
3.One local automatic object in main with Account ID 3333, initial balance $3000
4.One local static object in main with Account ID 4444, initial balance $4000
5.One local automatic object in main with Account ID 5555, initial balance $5000
6.One local automatic object in create() function with Account ID 6666, initial balance $6000
7.One local static object in create() function with Account ID 7777, initial balance $7000
8.One local automatic object in create() function with Account ID 8888, initial balance $8000
9.One local automatic object in main with Account ID 9999, initial balance $9000
Last edited on
Can anyone give me an example
Nah, this is too simple.

global -> outside a function
local -> inside a function
static -> this involves additionally the keyword static

See this

http://en.cppreference.com/w/cpp/keyword/static

for the meaning of static
three of them to get you started:

int global;
static int persists;
void foo()
{
int local;
}

Topic archived. No new replies allowed.