0% found this document useful (0 votes)
3 views8 pages

C Programming Exam Questions and Answers

This document presents a C programming exam consisting of 30 open-ended questions covering basic concepts of the C language such as loops, arrays, pointers, and functions. Some questions are worth more points than others.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

C Programming Exam Questions and Answers

This document presents a C programming exam consisting of 30 open-ended questions covering basic concepts of the C language such as loops, arrays, pointers, and functions. Some questions are worth more points than others.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

First name name

ISMIN 1A
Programming 1

C programming exam
Philippe LALEVÉE

January 7, 2010

Notes.
Please indicate your first name and last name at the top of this page.
You have one hour to answer the questions.
Documents are not allowed.
At the end of the exam, you will submit this paper, containing your answers.
This exam consists of 30 open-ended questions (short answers)
Annotated questions(*2) are worth double the points of non-annotated questions.
Those marked (*3) are worth triple points.
There is no downside.

1
Part 1. Open Questions

1.(*3)Consider the following code:


int i ;
for (i=0 ; i<10 ; i++) {
printf("i = %d\n", i) ;
}
Rewrite it using a while statement.

2.(*2) Give the declaration of an array where each of its 20 elements is a structure to
three fields: an integer number, an integer pointer, and an array of 15 characters.
Assuming this initialized table, give the expression to place in the field
Print the 4th element of the array, the address of the field number of the 11th element.

3.(*3) Here is the following code:


hello
int i ;
for (i=0 ; tab[i] != '\0' ; i++) {
tab[i] = tab[i] - 'a' + 'A';
}
What does this program do?

2
Propose a version without using the array access operator ([]).

4. In the following code:


char ch[] = "Hello", pc = ch *;
while ( pc)
* pc++;
What is pc worth after the execution of the while instruction? Which character does it point to?

What is the value of the variable at the end of the function?

void f(int i) {
int* j;
*j = i;
}

6. (*2) Why must we place an '&' in front of the variable 'ime' in the following code:
int ime;
scanf("%d", &ime);

7. Give an equivalent form to the expression.

What is the value of the variable in the following code?

3
float ill;
ille = 2/3 100.0
* ;

Why?

9.(*2) Give the expression C to calculate i = i * 2 .

10. Let the following declaration be: char les[] = "ab".


What are the values?

11. Let ge, an array of 10 characters. Provide the instruction to input from the keyboard a
string, without using the character '&'.

12.(*2) Here is the following code:


int i=0, tab[10], n=27 ;
do {
tab[i++] = n % 10;
} while ((n /= 10) > 10) ;
What does the program end table contain?

13.(*2) Here is the following code:


int i = 0, j = 5, sum = 20;
if (j && (i = sum / j) ) sum = 10 ;
else sum = 30;

4
Give the values of the variables after the execution of this program.

The strcpy function allows you to copy a string of characters into another existing one.
Here is its prototype:
char strcpy
* ( char destination,
* char source) *;
Write this function without using arrays or the [] operator (only pointers)
and pointer accesses).

15. In the following code:


int i=0, j=0 ;
j = ++i ;
What is the value of the variable after the assignment statement?

16. Let the following declaration be: char mant[] = { 'a', 'b' }.
What is worth it?

17. In the following code:


int i=0, j=0 ;
j = i++;
What is the value of the variable after the assignment statement?

5
18. Give the declaration of a function without parameters that returns the address of an integer.

19. Let the following declaration be: short ly[5] = {1, 2 }.


What is worthly[3]?

20. Let erne be an array of 10 integers. Provide the instruction to input the 3rd one from the keyboard.
whole

21. Give an equivalent form to the expression p->field.

22. Let the following declaration be int tab[10].


* Indicate what tab is?

23.(*2) What is the value of the variable flower in the following code:

char flower = 100 ;


fleuri = * 2 ;

Why?

24. Let the following declaration be, char tab[] = "". What does the array tab contain?

6
25. Give the declaration of a function without parameters that does not return any value.

26. Give the declaration of a pointer to an array of 10 strings.

27. What is the value of the variable 'ernet' at the end of the following code?

It should be recalled that x += y is equivalent to x = x + y and that generally, x op = y


is equivalent to x = xopy.
int ernet = 100;
ernet += 5 ;
ernet =* 10 ;
ernet /= 15 ;
ernet %= 4 ;

28.(*2) Here is the following code:


#include <stdio.h>
#define MAX = 10

int main() {
int tab[MAX];
tab[2] = 2 ;
printf("%d", tab[MAX-8]);
}
Does this program compile? If so, what does it display?

29.(*3) Here is the following code:


int i;
printf("i ? ");
scanf("%d", &i);
switch (i) {
case 0 : printf(" NUL") ; break ;
case 1 : case 3 : case 5 : case 7 : case 9 :
printf(" IMPAIR") ; break ;
case 2 : case 4 : case 6 : case 8 :
printf(" PAIR") ; break ;

7
default: printf("NEGATIVE OR NOT A NUMBER"); break;
}
Rewrite the switch instructions using only if statements.

30.(*2) Here is the following code:


void g(int p) {*
* p = 12 ;
}

int main() {
int p* ;
g(p) ;
printf("%d\n", p); *
}
What is displayed?

You might also like