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