Table of Contents

C/C++ Programming Knowledge Assessment

0x0

For the following values, list the smallest possible C data type it can fit into:

0x1

Analyze the following code, and answer the questions:

1
#include <stdio.h>
#define SIZE 31
 
int main()
{
    char data[SIZE];
    int i;
 
    printf("Enter a string of up to %d letters (upper and lowercase), NO spaces: ", (SIZE-1));
    scanf("%s", data);
 
    for(i = 0; i < SIZE; i++)
    {   
        if (data[i] != 0)
        {
            if ((data[i] == 97) || (data[i] == 101) || (data[i] == 105) || (data[i] == 111) || (data[i] == 117))
            {
                data[i] = data[i] - 32;
            }
        }
        else
        {
            break;
        }
    }
 
    printf("After processing, the string is: %s\n", data);
 
    return(0);
}

0x2

Analyze the following code, and answer the questions:

1
#include <stdio.h>
#define SIZE 31
 
int main()
{
    char data[SIZE];
    int i, j = 0;
 
    printf("Enter a string of up to %d letters (upper and lowercase), NO spaces: ", (SIZE-1));
    scanf("%s", data);
 
    for(i = 0; i < SIZE; i++)
    {
        if (data[i] != 0)
        {
            if ((data[i] == 101) || (data[i] == 69))
            {
                j = j + 1;
            }
        }
        else
        {
            break;
        }
    }
 
    printf("After processing, j is: %d\n", j);
 
    return(0);
}

0x3

Analyze the following code, and answer the questions:

1
#include <stdio.h>
#define SIZE 31
 
int main()
{
    char data[SIZE];
    int i, j = 0, k = 0;
 
    printf("Enter a string of up to %d letters (upper and lowercase), NO spaces: ", (SIZE-1));
    scanf("%s", data);
 
    for(i = 0; i < SIZE; i++)
    {
        if (data[i] != 0)
        {
            if ((data[i] >= 65) && (data[i] <= 90))
            {
                j = j + data[i];
                k++;
            }
        }
        else
        {
            break;
        }
    }
 
    i = j / k;
    j = i;
 
    printf("After processing, j is: %c\n", j);
 
    return(0);
}

0x4

Analyze the following code, and answer the questions:

1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
#define SIZE 31
 
int main()
{
    char data[SIZE];
    int i, j = -1, k = 0;
 
    srand(time(NULL));
 
    for(i = 0; i < SIZE; i++)
    {
        data[i] = rand() % 2599 + 1;
    }
 
    for(i = 0; i < SIZE; i++)
    {
        if (data[i] > j)
            j = data[i];
    }
 
    printf("After processing, j is: %d\n", j);
 
    return(0);
}