0% found this document useful (0 votes)
23 views2 pages

Tipuri de Date

1) The document defines variables of basic data types (char, int, float, double) and initializes them. It then prints their values and sizes. 2) It demonstrates pointers to basic data types, including void pointers, and pointers to dynamically allocated memory. 3) It shows multi-dimensional arrays and loops through elements of a 2D array.

Uploaded by

Adriana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Tipuri de Date

1) The document defines variables of basic data types (char, int, float, double) and initializes them. It then prints their values and sizes. 2) It demonstrates pointers to basic data types, including void pointers, and pointers to dynamically allocated memory. 3) It shows multi-dimensional arrays and loops through elements of a 2D array.

Uploaded by

Adriana
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1: #include <stdio.

h>
2: #include <iostream>
3: #include <stdlib.h>
4:
5: using namespace std;//pt scrierea prescurtata, fara std::cout, etc
6:
7: int main()
8: {
9: //date de baza
10: char c1, c2 = 'A';//tipul char
11: int i1, i2 = 10;//tipul int
12: float f1, f2 = 1.2;//tipul float
13: double d1, d2 = 1.e-4;//tipul double
14: printf("%c\t%d\t%3.1f\t%g\n", c2, i2, f2, d2);//in stdio
15: cout << c2 << "\t" << i2 << "\t" << f2 << "\t" << d2 << endl;//in iostream
16: cout << "char: " << sizeof(c2) << "\t" << "int: " << sizeof(i2) << "\t" <<
"float: " << sizeof(f2) << "\t" << "double: " << sizeof(d2) << "\tOcteti" <<
endl;
17:
18: //ponteri
19: //void
20: void *pv;
21: pv = &i2;
22: printf("%d\n",*(int*)pv);
23: cout << *(int*)pv << endl;//convertirea tipului void - modificator de tip
24:
25: //pt un tip definit, si anume int
26: int *p;
27: int a = 10;
28: p = &a;//adresa lui a
29: *p = 20;// continutul memoriei de la adresa punctata de p
30: cout << *p << "\t" << a << endl;
31:
32: int *p1 = new int;//alocare zona memorie, al carei continut il reprezinta
un intreg, adresa ei fiind reprezentata de p1
33: *p1 = 30;
34: cout << *p1 << endl;
35: delete p1;//obligatoriu, datorita alocarii memoriei pt pointerul p1
36:
37: /*
38: int *p1;
39: p1 = (int *)malloc(1 * sizeof(int));
40: *p1 = 55;
41: cout << *p1 << endl;
42: free(p1);
43: */
44:
45:
46: //tablouri
47: int tablou1[4] = {1, 2, 3}, tablou2[][2][3] = {1}, tablou3[2][2] = {1, 2,
3};
48:
49: int i, j;
50:
51: cout << tablou1[2] << "\t" << *(tablou1+2) << endl << endl;
52:
53: for(i = 0; i < 2; i++)
54: {
55: for(j = 0; j < 2; j++) cout << tablou3[i][j] << "\t";
56: cout << endl;
57: }
58:
59:
60: system("PAUSE");//in stdlib
61: return 0;
62: }
63:
64:
65:
66:
67:
68:

You might also like