Jump to content
everton

problema c++

Recommended Posts

Posted

cum pot face cu cout sa vad locatia unei variabile in memorie cu printf se folosea & dar dak dau cu cout de ex: cout<<&variabila imi apar doar prostii

dar daca dau de exemplu :

int main()

{

char a[2],b[2];

cout<<&a<<"\n";

cout<<&b;

getch();

return 0;

}

atunci imi apare locatia in memorie

Posted

Care e problema, ce prostii iti apar?

0xbf9543fe e ok, e in hexa. (32bit compilat cu bcc32)

0xfff4 e ok (16 bit, compilat cu bcc)

& nu se folosea din cauza printf ci se foloseste intotdeauna in C pentru adresa variabilelor.

Nu iti va afisa niciodata adresa reala, ci adresa in segmentul de memorie in care isi memoreaza datele.

Posted

#include <iostream>
using namespace std;

int main()
{
unsigned long x, y[10];
x = 4;
y[0] = 0;
y[1] = 1;
cout << x << " " << &x << " " << int(&x);
cout << "\n";
cout << y << " " << &y; // cu sau fara & e tot aia ca y e pointer
cout << " " << &y[0];
system("pause >NUL");
return 0;
}

Foloseste int(&var) pentru a vedea valoarea respectiva in baza 10, prin prostie cum zicea si loki cred ca te referi ca ti-o arata in baza 16.

EDIT:

Inseamna ca iti face char() de ceva care este >127.

Posted

ciudat, ori e diferenta de compilator ori tu de fapt ai alt program in fata.

cout<<a<<"\n"; cred ca ti-ar putea da un asemenea rezultat aiurea atat timp cat tu nu ai pus valori in a[] si b[]. Iti afiseaza date la intamplare gasite in memorie.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...