GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Basic definitions

Jozsef Gabris Programming Englisch 24 Karten

Karten in diesem Stapel (24)

  1. 1How to define enums?enum Days {
    Sunday,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday
    };
  2. 2How to use enums?void main()
    {
    enum Days MyDay;
    MyDay = Sunday;
    printf("Sunday = %d\n", MyDay);
    MyDay = Tuesday;
    printf("Tuesday = %d\n", MyDay);
    }
  3. 3Defining a For loopfor (int i = 1; i <= 10; ++i)
    printf("%d x %d = %d\n", number, i, number * i);
  4. 4Defining a procedure//Procedure: returns nothing
    void SayHello()
    {
    printf("Hello, World!\n");
    }
  5. 5Defining a functionint Sum(int a, int b)
    {
    int result = a + b;
    return result;
    }
  6. 6Defining while loopint i = 0;
    while (i < 32)
    {
    printf("%d = %x\n", i, i);
    i++;
    }
  7. 7Defining do whle loopint i = 0;
    do
    {
    printf(" i = %d\n", i);
    i++;
    } while ( i < 10 );
  8. 8Defining arrays (vector)int a[] = { 30, 50, 10, 40, 20, 6, 2, 65 };
  9. 9Getting the size of an arrayint size = sizeof(a) / sizeof(a[0]);
  10. 10Sum of the element of an arrayint SumElements(int ar[], int size)
    {
    //Sum all elements of an array
    int sum = 0;
    for (int i = 0; i < size; ++i)
    {
    sum += ar[i];
    }
    return sum;
    }
  11. 11Print arrayint PrintArray(int ar[], int size)
    {
    for (int i = 0; i < size; ++i)
    {
    printf("Element at [%d] = %d\n", i, ar[i]);
    }
    }
  12. 12Finding the max value of an arrayint FindMax(int a[], int size)
    {
    int max = a[0];
    for (int j = 1; j < size; ++j)
    {
    if (a[j] > max)
    max = a[j];
    }
    return max;
    }
  13. 13Defining 2D arrayint a[3][2] = { {0,1},
    {2,3},
    {4,5}
    };
  14. 14Printing 2D arrayfor (int i = 0; i < 3; ++i)
    {
    for (int j = 0; j < 2; ++j)
    {
    printf("a[%d][%d] = %d ", i, j, a[i][j]);
    }
    printf("\n");
    }
  15. 15Address of operator:&
    print with %p
  16. 16Declare integer pointer and make it point to aint* p = &a;
  17. 17Modify integer value at address inside pointer*p = 15;
  18. 18Header needed for string functions:#include
  19. 19Copying a stringstrcpy_s(str, ARRAYSIZE(str), "This is a string with 1");
  20. 20Writing to a string:strcat_s(str, ARRAYSIZE(str), "00. this is done with strcat");
  21. 21Printing to a string:sprintf_s(mystr, ARRAYSIZE(mystr), "This is an example with two integers %d + %d = %d\n", a, b, a + b);
  22. 22Case sensitive string comparison:// strcmp returns:
    // < 0: if p1 < p2
    // 0: if p1 == p2
    // > 0: if p1 > p2
    int result = strcmp(p1, p2);
  23. 23Function is used to search for a character inside a string// Look for letter 'f'
    char* pf = strchr(str1, 'f');
  24. 24Case insensitive comparisonif (0 == _stricmp(str1, "SuM"))
    {
    printf("Let's do a sum operation\n");
    }

Informationen

Beschreibung
Programming (C) Karteikarten am Basic definitions, erstellt von Jozsef Gabris am 14/04/2017.
Erstellt von
Jozsef Gabris
Aufrufe
1
Bewertung

Mehr zu C Programming Basics

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck