Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. Test Revision
  2.  
  3. Fundamentals
  4.  
  5. integer 4 Bytes
  6. int %d
  7. int x = 50;
  8.  
  9. float 4 Bytes
  10. float %f
  11.  
  12. character 1 Byte
  13. char %c
  14. char grade = '9';
  15. char grade = 'A' 9 =/= '9'
  16.  
  17.  
  18. string
  19. char[] %s
  20.  
  21. => char name[256] = "Keeley";
  22.  
  23.  
  24.  
  25. a = 14;
  26. b = 10;
  27. ////CASE 0
  28. j = ++a + ++b ; // j = 15 + 11 = 26
  29. printf("%d",a); // a = 15
  30. /////CASE 1
  31. j = a++ + ++b ; // j = 14 + 11 = 25
  32. printf("%d",a); // a = 15
  33. ////
  34.  
  35.  
  36.  
  37. Variables
  38. dont start with number
  39. cannot use reserved words
  40. no spaces
  41. no special characters except $ and _
  42.  
  43. int voLatile;
  44.  
  45.  
  46.  
  47. Operators
  48.  
  49. x++;
  50. ++x;
  51.  
  52. x = x + 1
  53. x += 1
  54.  
  55. x *= 3
  56. x /= 3
  57. x -= 3
  58.  
  59.  
  60. --x;
  61. x--;
  62.  
  63.  
  64.  
  65. Arrays
  66. double x[2][2] = {1.,2.,3.,4.} ;
  67.  
  68. type double
  69. no of elements 4
  70. name x
  71. dimensions 2
  72.  
  73. Constant
  74.  
  75. #define PI 3.14
  76.  
  77. const float pi = 3.14;
  78.  
  79. I/O
  80. input:
  81. int a;
  82. char name[] = "Name"; // Works but unadvisable
  83.  
  84. scanf("%s",name);
  85.  
  86. scanf("%d",&a);
  87.  
  88. scanf("%d",&a);
  89.  
  90.  
  91.  
  92. output:
  93. printf("%d",a);
  94.  
  95.  
  96. Design
  97. Pseudo Code
  98.  
  99.  
  100. output "Please input x"
  101. input x
  102.  
  103.  
  104. x <- x + 1
  105.  
  106. output "x is " <- x
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. Flow Charts
  115.  
  116. 4 shapes:
  117.  
  118.  
  119. diamond : test conditions
  120. "x > 3"
  121.  
  122. square : statements
  123. x = pi*r^2 ;
  124.  
  125.  
  126.  
  127.  
  128. parallelogram : I / O
  129. print "X is " <- x
  130.  
  131. scan x
  132.  
  133.  
  134.  
  135. oval: start / end
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. Control
  143. if - else
  144.  
  145. 1. nested
  146. if(cond_1)
  147. {
  148. if(cond_2)
  149. {
  150.  
  151. }
  152. }
  153.  
  154. 2. single branching
  155. if (cond_1)
  156. {
  157.  
  158. }
  159.  
  160. 3. dual branching
  161. if(cond_1)
  162. {
  163.  
  164. }
  165. else
  166. {
  167.  
  168. }
  169.  
  170. 4. chaining or cascading
  171. if(cond_1)
  172. {
  173.  
  174. }
  175. else if (cond_2)
  176. {
  177.  
  178. }
  179. else if (cond_3)
  180. {
  181.  
  182. }
  183. else if (cond_n)
  184. {
  185.  
  186. }
  187. else
  188. {
  189. printf("error");
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197. switch
  198. int, char ONLY
  199.  
  200.  
  201. int x;
  202. switch(x)
  203. {
  204. case 10: case 9:
  205. printf("A");
  206. break;
  207.  
  208. case 5: case 6: case 7: case 8:
  209. printf("B");
  210. break;
  211.  
  212. default:
  213. printf("Error");
  214.  
  215.  
  216. }
  217.  
  218. #include <stdio.h>
  219. int main(void)
  220. {
  221. int ph;
  222. printf("enter ph");
  223. scanf("%d",&ph);
  224.  
  225. switch(ph)
  226. {
  227. case 8 ... 12:
  228. printf("Alkaline");
  229. break;
  230. case 7:
  231. printf("neutral");
  232. break;
  233. case 2: case 3: case 4: case 5: case 6:
  234. printf("Acid");
  235. break;
  236. default
  237. printf("error");
  238. }
  239. return 0;
  240. }
  241.  
  242.  
  243. Repetition
  244.  
  245. for
  246. int ii;
  247.  
  248.  
  249. (start; stop; step)
  250. (initial; condition; increment)
  251.  
  252. for(ii = 0; ii< 10; ii++)
  253. {
  254.  
  255. }
  256.  
  257. do while 1 to many
  258.  
  259. do
  260. {
  261.  
  262. }while(x>5);
  263.  
  264.  
  265. while 0 to many
  266.  
  267.  
  268. while(x>5)
  269. {
  270.  
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement