C programming Flashcards

Be able to read codes in C language

1
Q

include

Consider the following program, written in C:

char *grumble(char *s) {
    for (int i=0; s[i]; i++)
         if (s[i] >= 'A' &amp;&amp; s[i] <= 'Z')
             s[i] = s[i] -'A' + 'a';
    return s;
}
int main() {
char line[] = "Good Question!";
printf("'%s'\n", grumble(line));
}

What is the output from this program?

A

Answer:

‘good question!’

remark:
makes the upper case letter to lower case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

My C program contains the declaration:

char c = ‘B’ –‘a’ + ‘c’;

What is the value of variable c?

A

Answer: ‘D’

'B' = 66 
'a' = 97
'c' = 99

char c = ‘B’ –‘a’ + ‘c’;
c = 66 - 97 + 99
c = 68
c = ‘D’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly