Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Test Revision
- Fundamentals
- integer 4 Bytes
- int %d
- int x = 50;
- float 4 Bytes
- float %f
- character 1 Byte
- char %c
- char grade = '9';
- char grade = 'A' 9 =/= '9'
- string
- char[] %s
- => char name[256] = "Keeley";
- a = 14;
- b = 10;
- ////CASE 0
- j = ++a + ++b ; // j = 15 + 11 = 26
- printf("%d",a); // a = 15
- /////CASE 1
- j = a++ + ++b ; // j = 14 + 11 = 25
- printf("%d",a); // a = 15
- ////
- Variables
- dont start with number
- cannot use reserved words
- no spaces
- no special characters except $ and _
- int voLatile;
- Operators
- x++;
- ++x;
- x = x + 1
- x += 1
- x *= 3
- x /= 3
- x -= 3
- --x;
- x--;
- Arrays
- double x[2][2] = {1.,2.,3.,4.} ;
- type double
- no of elements 4
- name x
- dimensions 2
- Constant
- #define PI 3.14
- const float pi = 3.14;
- I/O
- input:
- int a;
- char name[] = "Name"; // Works but unadvisable
- scanf("%s",name);
- scanf("%d",&a);
- scanf("%d",&a);
- output:
- printf("%d",a);
- Design
- Pseudo Code
- output "Please input x"
- input x
- x <- x + 1
- output "x is " <- x
- Flow Charts
- 4 shapes:
- diamond : test conditions
- "x > 3"
- square : statements
- x = pi*r^2 ;
- parallelogram : I / O
- print "X is " <- x
- scan x
- oval: start / end
- Control
- if - else
- 1. nested
- if(cond_1)
- {
- if(cond_2)
- {
- }
- }
- 2. single branching
- if (cond_1)
- {
- }
- 3. dual branching
- if(cond_1)
- {
- }
- else
- {
- }
- 4. chaining or cascading
- if(cond_1)
- {
- }
- else if (cond_2)
- {
- }
- else if (cond_3)
- {
- }
- else if (cond_n)
- {
- }
- else
- {
- printf("error");
- }
- switch
- int, char ONLY
- int x;
- switch(x)
- {
- case 10: case 9:
- printf("A");
- break;
- case 5: case 6: case 7: case 8:
- printf("B");
- break;
- default:
- printf("Error");
- }
- #include <stdio.h>
- int main(void)
- {
- int ph;
- printf("enter ph");
- scanf("%d",&ph);
- switch(ph)
- {
- case 8 ... 12:
- printf("Alkaline");
- break;
- case 7:
- printf("neutral");
- break;
- case 2: case 3: case 4: case 5: case 6:
- printf("Acid");
- break;
- default
- printf("error");
- }
- return 0;
- }
- Repetition
- for
- int ii;
- (start; stop; step)
- (initial; condition; increment)
- for(ii = 0; ii< 10; ii++)
- {
- }
- do while 1 to many
- do
- {
- }while(x>5);
- while 0 to many
- while(x>5)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement