Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <limits>
- #include <complex>
- #include <vector>
- using namespace std;
- enum { ASM , AUTO , BREAK };
- int main ()
- {
- std::string name = "Stoyan";
- std::cout << "Hello, new world!\n";
- printf("name: %s \ n ",name.c_str());
- string str;
- cout << "P l e a s e e n t e r y o u r n a m e \ n ";
- cin >> str ;
- cout << "H e l l o , " << str << "!\ n ";
- cout << "largestfloat == " << numeric_limits<float>::max() << ", char is signed == " << numeric_limits<char>::is_signed << '\n';
- // void x; // error: there are no void objects
- // void f(); // function f does not return a value (§7.3)
- void* pv; // pointer to object of unknown type (§5.6)
- typedef char* Pchar; // A declaration prefixed by the keyword t y p e d e f declares a new name for the type rather than a new variable of the given type.
- Pchar p1, p2; // p1 and p2 are char*s
- char* p3 = p1;
- cout << "beep at end of message \a\n";
- }
- char ch;
- string s;
- int count = 1;
- const double pi = 3.1415926535897932385;
- extern int error_number;
- char* name = "Njal";
- char* season[] = { "s p r i n g ", "s u m m e r ", "f a l l ", "w i n t e r " };
- struct Date { int d, m, y; };
- int day(Date* p) { return p ->d; }
- double sqrt(double);
- template<class T> T abs(T a) { return a<0 ? -a : a; }
- typedef std::complex<short> Point; // t y p e d e f declares a new name for the type rather than a new variable of the given type
- struct User;
- enum Beer { Carlsberg , Tuborg , Thor };
- namespace NS { int a; }
- // typedef A name defined like this, usually called a ‘‘ t y p e d e f ,’’ can be a convenient shorthand for a type
- // with an unwieldy name. For example, u n s i g n e d c h a r is too long for really frequent use, so we
- // could define a synonym, u c h a r :
- typedef unsigned char uchar;
- // Another use of a t y p e d e f is to limit the direct reference to a type to one place. For example:
- typedef int int32;
- typedef short int16;
- char c = 'a';
- char* p = &c; // p holds the address of c
- // Unfortunately, pointers to arrays and pointers to functions need a more complicated notation:
- int* pi1; // pointer to int
- char** ppc; // pointer to pointer to char
- int* ap[15]; // array of 15 pointers to ints
- int (*fp)(char*); // pointer to function taking a char* argument; returns an int
- int* f(char*); // function taking a char* argument; returns a pointer to int
- // The fundamental operation on a pointer is dereferencing, that is, referring to the object pointed
- // to by the pointer. This operation is also called indirection. The dereferencing operator is (prefix)
- // unary *. For example:
- char c1 = 'a';
- char* p1 = &c1 ; // p holds the address of c
- char c2 = *p1 ; // c2 == ’a’
- float v[3]; // an array of three floats: v[0], v[1], v[2]
- char* a[32]; // an array of 32 pointers to char: a[0] .. a[31]
- void f (int i)
- {
- int v1[i]; // error: array size not a constant expression
- vector<int> v2(i); // ok
- }
- // An array can be initialized by a list of values. For example:
- int v1[] = { 1 , 2 , 3 , 4 };
- char v2[] = { 'a', 'b', 'c', 0 };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement