K
K
konovalik2015-11-30 19:49:25
C++ / C#
konovalik, 2015-11-30 19:49:25

What is the difference between declarations (pointers and variables)?

Dear experts!
What happens in memory, and why is it even needed?

int i;
int i*;
int i* = new double;
int i = new double*;

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
MiiNiPaa, 2015-11-30
@MiiNiPaa

1) One variable of type int is created in automatic memory with the name i. The value of i is not defined.
2) Syntax error, perhaps you mean int* i;? In this case, a variable of type int* is created in automatic memory with the name i. The value of i is not defined.
3) Syntax error, perhaps you meant int* i = new int;? In this case, a variable of type int* is created in automatic memory with the name i. Then a variable of type int is created in heap memory, and i is assigned the address of this newly created variable.
4) Syntax error. I have no idea what was meant.

A
Anatoly Medvedev, 2015-11-30
@balamyt92

times two , read friend.

O
Oleg Tsilyurik, 2015-11-30
@Olej

What happens in memory, and why is it even needed?

It's impossible to explain it in 10 words... and it's also impossible on one page...
Until you seriously study the ideology of pointers, it's pointless to discuss particular syntactic constructions:
int *****p;
*****p = 1234;
z->xy=...;
(*z).xy = ...;
All such things you must learn "on the fly."
Discussing these issues in a toster is a pointless exercise.

I
iv_k, 2015-12-01
@iv_k

1. a thought process takes place in memory
2. why it is necessary to ask you at all. what did you want to write?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question