GoConqr has a new look! Let us know what you think.

Flashcards

Basic definitions

Jozsef Gabris Programming English 24 cards

Cards in this deck (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");
    }

Information

Description
Programming (C) Flashcards on Basic definitions, created by Jozsef Gabris on 14/04/2017.
Created by
Jozsef Gabris
Views
1
Rating

More on C Programming Basics

Feedback

What is it about?

What do you think of the new look?

How do you like it?