Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int x;
- int a, b, c, d;
- char letter;
- float the_float;
- const float pi = 3.14;
- printf( "I am alive! Beware.\n" );
- int this_is_a_number;
- printf( "Please enter a number: " );
- scanf( "%d", &this_is_a_number ); //%d = integer
- printf( "%d is an integer\n", this_is_a_number );
- if (0 == 0)
- {
- printf("You passed");
- }
- else
- {
- printf("You failed");
- }
- char fruit;
- printf("Which one is your favourite fruit:\n");
- printf("a) Apples\n");
- printf("b) Bananas\n");
- printf("c) Cherries\n");
- scanf("%c",&fruit);
- switch (fruit)
- {
- case 'a':
- printf("You like apples\n");
- break;
- case 'b':
- printf("You like bananas\n");
- break;
- case 'c':
- printf("You like cherries\n");
- break;
- default:
- printf("You entered an invalid choice\n");
- }
- getchar();
- return 0;
- }
- /*
- Name Type Range
- int Numeric - Integer -32,768 to 32,767
- short Numeric - Integer -32,768 to 32,767
- long Numeric - Integer -2,147,483,648 to 2,147,483,647
- float Numeric - Real 1.2 X 10^-38 to 3.4 X 10^38
- double Numeric - Real 2.2 X 10^-308 to 1.8 X 10^308
- char Character All ASCII characters
- */
- /*
- scanf("%d",&a);
- printf("The answer is %d",a);
- %d or %i int
- %c char
- %f float
- %lf double
- %s string */
- /*
- == Equal
- != Not equal
- > Greater than
- >= Greater than or equal
- < Less than
- <= Less than or equal
- && And
- || Or
- ! Not
- */
- /*
- do
- {
- i++;
- printf("%d\n",i);
- }
- while (i <= times);
- */
- /*
- int i,j;
- int *p;
- i = 5;
- p = &i;
- j = *p; //j = i
- *p = 7; //i = 7
- int a[3][3],i,j;
- for (i = 0;i < 3;i++)
- for (j = 0;j < 3;j++)
- a[i][j] = 0;
- char ca[10];
- 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.
- char ca[10];
- ca[0] = 'H';
- ca[1] = 'e';
- ca[2] = 'l';
- ca[3] = 'l';
- ca[4] = 'o';
- ca[5] = 0;
- printf("%s",ca);
- String pointers are declared as a pointer to a char.
- char *sp;
- When you assign a value to the string pointer it will automatically put the 0 in for you unlike character arrays.
- char *sp;
- sp = "Hello";
- printf("%s",sp);
- 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.
- char ca[10],*sp;
- scanf("%s",ca);
- sp = ca;
- scanf("%s",sp);
- Functions:
- int mult ( int x, int y );
- int main()
- {
- return 0;
- }
- int mult (int x, int y)
- {
- return x * y;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement