Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int x;
  6. int a, b, c, d;
  7. char letter;
  8. float the_float;
  9. const float pi = 3.14;
  10.  
  11. printf( "I am alive! Beware.\n" );
  12.  
  13. int this_is_a_number;
  14. printf( "Please enter a number: " );
  15. scanf( "%d", &this_is_a_number ); //%d = integer
  16. printf( "%d is an integer\n", this_is_a_number );
  17.  
  18. if (0 == 0)
  19. {
  20. printf("You passed");
  21. }
  22. else
  23. {
  24. printf("You failed");
  25. }
  26.  
  27. char fruit;
  28. printf("Which one is your favourite fruit:\n");
  29. printf("a) Apples\n");
  30. printf("b) Bananas\n");
  31. printf("c) Cherries\n");
  32. scanf("%c",&fruit);
  33. switch (fruit)
  34. {
  35. case 'a':
  36. printf("You like apples\n");
  37. break;
  38. case 'b':
  39. printf("You like bananas\n");
  40. break;
  41. case 'c':
  42. printf("You like cherries\n");
  43. break;
  44. default:
  45. printf("You entered an invalid choice\n");
  46. }
  47.  
  48. getchar();
  49.  
  50. return 0;
  51. }
  52.  
  53. /*
  54. Name Type Range
  55. int Numeric - Integer -32,768 to 32,767
  56. short Numeric - Integer -32,768 to 32,767
  57. long Numeric - Integer -2,147,483,648 to 2,147,483,647
  58. float Numeric - Real 1.2 X 10^-38 to 3.4 X 10^38
  59. double Numeric - Real 2.2 X 10^-308 to 1.8 X 10^308
  60. char Character All ASCII characters
  61. */
  62.  
  63. /*
  64. scanf("%d",&a);
  65. printf("The answer is %d",a);
  66. %d or %i int
  67. %c char
  68. %f float
  69. %lf double
  70. %s string */
  71.  
  72. /*
  73. == Equal
  74. != Not equal
  75. > Greater than
  76. >= Greater than or equal
  77. < Less than
  78. <= Less than or equal
  79. && And
  80. || Or
  81. ! Not
  82. */
  83.  
  84. /*
  85. do
  86. {
  87. i++;
  88. printf("%d\n",i);
  89. }
  90. while (i <= times);
  91. */
  92.  
  93. /*
  94. int i,j;
  95. int *p;
  96. i = 5;
  97. p = &i;
  98. j = *p; //j = i
  99. *p = 7; //i = 7
  100.  
  101.  
  102.  
  103. int a[3][3],i,j;
  104. for (i = 0;i < 3;i++)
  105. for (j = 0;j < 3;j++)
  106. a[i][j] = 0;
  107.  
  108.  
  109.  
  110. char ca[10];
  111.  
  112. You must set the value of each individual element of the array to the character you want and you must make the last character a 0. Remember to use %s when printing the string.
  113.  
  114. char ca[10];
  115. ca[0] = 'H';
  116. ca[1] = 'e';
  117. ca[2] = 'l';
  118. ca[3] = 'l';
  119. ca[4] = 'o';
  120. ca[5] = 0;
  121. printf("%s",ca);
  122.  
  123. String pointers are declared as a pointer to a char.
  124.  
  125. char *sp;
  126.  
  127. When you assign a value to the string pointer it will automatically put the 0 in for you unlike character arrays.
  128.  
  129. char *sp;
  130. sp = "Hello";
  131. printf("%s",sp);
  132.  
  133. You can read a string into only a character array using scanf and not a string pointer. If you want to read into a string pointer then you must make it point to a character array.
  134.  
  135. char ca[10],*sp;
  136. scanf("%s",ca);
  137. sp = ca;
  138. scanf("%s",sp);
  139.  
  140.  
  141.  
  142.  
  143. Functions:
  144. int mult ( int x, int y );
  145.  
  146. int main()
  147. {
  148. return 0;
  149. }
  150.  
  151. int mult (int x, int y)
  152. {
  153. return x * y;
  154. }
  155. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement