Advertisement
wingman007

HelloWorldC

May 6th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. #include <stdio.h>
  2. main()
  3. {
  4.     printf("hello, world\n");
  5. }
  6.  
  7. /* c++
  8. #include <iostream>
  9. #include <string>
  10. #include <limits>
  11. #include <complex>
  12. #include <vector>
  13.  
  14. using namespace std;
  15.  
  16. enum { ASM , AUTO , BREAK };
  17.  
  18. int main ()
  19. {
  20.     std::string name = "Stoyan";
  21.     std::cout << "Hello, new world!\n";
  22.     printf("name: %s \ n ",name.c_str());
  23.    
  24.     string str;
  25.     cout << "P l e a s e e n t e r y o u r n a m e \ n ";
  26.     cin >> str ;
  27.     cout << "H e l l o , " << str << "!\ n ";
  28.    
  29.     cout << "largestfloat == " << numeric_limits<float>::max() << ", char is signed == " << numeric_limits<char>::is_signed << '\n';
  30.    
  31.    
  32.     // void x; // error: there are no void objects
  33.     // void f(); // function f does not return a value (§7.3)
  34.     void* pv; // pointer to object of unknown type (§5.6)
  35.    
  36.     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.
  37.     Pchar p1, p2; // p1 and p2 are char*s
  38.     char* p3 = p1;
  39.     cout << "beep at end of message \a\n";
  40. }
  41.  
  42. char ch;
  43. string s;
  44. int count = 1;
  45. const double pi = 3.1415926535897932385;
  46. extern int error_number;
  47.  
  48. char* name = "Njal";
  49. char* season[] = { "s p r i n g ", "s u m m e r ", "f a l l ", "w i n t e r " };
  50.  
  51. struct Date { int d, m, y; };
  52. int day(Date* p) { return p ->d; }
  53. double sqrt(double);
  54. template<class T> T abs(T a) { return a<0 ? -a : a; }
  55. 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
  56. struct User;
  57. enum Beer { Carlsberg , Tuborg , Thor };
  58. namespace NS { int a; }
  59.  
  60. // typedef A name defined like this, usually called a ‘‘ t y p e d e f ,’’ can be a convenient shorthand for a type
  61. // 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
  62. // could define a synonym, u c h a r :
  63. typedef unsigned char uchar;
  64.  
  65. // 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:
  66. typedef int int32;
  67. typedef short int16;
  68.  
  69. char c = 'a';
  70. char* p = &c; // p holds the address of c
  71.  
  72. // Unfortunately, pointers to arrays and pointers to functions need a more complicated notation:
  73. int* pi1; // pointer to int
  74. char** ppc; // pointer to pointer to char
  75. int* ap[15]; // array of 15 pointers to ints
  76. int (*fp)(char*); // pointer to function taking a char* argument; returns an int
  77. int* f(char*); // function taking a char* argument; returns a pointer to int
  78.  
  79. // The fundamental operation on a pointer is dereferencing, that is, referring to the object pointed
  80. // to by the pointer. This operation is also called indirection. The dereferencing operator is (prefix)
  81. // unary *. For example:
  82. char c1 = 'a';
  83. char* p1 = &c1 ; // p holds the address of c
  84. char c2 = *p1 ; // c2 == ’a’
  85.  
  86.  
  87. float v[3]; // an array of three floats: v[0], v[1], v[2]
  88. char* a[32]; // an array of 32 pointers to char: a[0] .. a[31]
  89.  
  90. void f (int i)
  91. {
  92. int v1[i]; // error: array size not a constant expression
  93. vector<int> v2(i); // ok
  94. }
  95.  
  96. // An array can be initialized by a list of values. For example:
  97. int v1[] = { 1 , 2 , 3 , 4 };
  98. char v2[] = { 'a', 'b', 'c', 0 };
  99.  
  100. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement