100% found this document useful (1 vote)
152 views2 pages

C Questions 15 Good Ones

The document contains 14 embedded questions about C programming concepts including: 1) Declaring a manifest constant for seconds in a year using #define 2) The purpose of the #error preprocessor directive 3) Defining various variable types like integers, pointers, and arrays 4) The meaning of const qualifiers in variable declarations 5) The meaning and uses of the volatile keyword 6) Whether a parameter can be both const and volatile 7) Whether a pointer can be volatile 8) An error in a function that uses a volatile pointer parameter 9) Code to set an integer variable to an absolute address 10) Code to set or clear a specific bit in an integer variable 11) Usage

Uploaded by

kokarako
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
152 views2 pages

C Questions 15 Good Ones

The document contains 14 embedded questions about C programming concepts including: 1) Declaring a manifest constant for seconds in a year using #define 2) The purpose of the #error preprocessor directive 3) Defining various variable types like integers, pointers, and arrays 4) The meaning of const qualifiers in variable declarations 5) The meaning and uses of the volatile keyword 6) Whether a parameter can be both const and volatile 7) Whether a pointer can be volatile 8) An error in a function that uses a volatile pointer parameter 9) Code to set an integer variable to an absolute address 10) Code to set or clear a specific bit in an integer variable 11) Usage

Uploaded by

kokarako
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

C & Embedded Questions

1. Using the #define statement, how would you declare a manifest constant that
returns the number of seconds in a year? Disregard leap years in your
answer.
2. What is the purpose of the preprocessor directive #error?
3. Using the variable a, give definitions for the following:
a) An integer
b) A pointer to an integer
c) A pointer to a pointer to an integer
d) An array of 10 integers
e) An array of 10 pointers to integers
f) A pointer to an array of 10 integers
g) A pointer to a function that takes an integer as an argument and returns
an integer
h) An array of ten pointers to functions that take an integer argument and
return an integer
4. what do the following declarations mean?
const int a;
int const a;
const int *a;
int * const a;
int const * a const;
5. What does the keyword volatile mean? Give three different examples of its
use.
6. Can a parameter be both const and volatile ? Explain.
7. Can a pointer be volatile ? Explain.
8. What's wrong with the following function?:

int square(volatile int *ptr)


{
return *ptr * *ptr;
}
9. On a certain project it is required to set an integer variable at the absolute
address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler.
Write code to accomplish this task.
10. Given an integer variable a, write two code fragments. The first should set bit 3 of
a. The second should clear bit 3 of a. In both cases, the remaining bits should be
unmodified.
11. The following code uses __interrupt to define an interrupt service routine (ISR).
Comment on the code.
__interrupt double compute_area
(double
radius)
{
double area = PI * radius * radius;
printf("\nArea = %f", area);
return area;
}
12. what does the following code output and why?
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") : puts("<= 6");
}

13. Comment on the following code fragment.

unsigned int zero = 0;


unsigned int compzero = 0xFFFF;
/*1's complement of zero */

13. What does the following code fragment output and why?

char *ptr;
if ((ptr = (char *)malloc(0)) == NULL)
puts("Got a null pointer");
else
puts("Got a valid pointer");

14. Typedef is frequently used in C to declare synonyms for pre-existing data types.
It is also possible to use the preprocessor to do something similar. For instance,
consider the following code fragment:

#define dPS struct s *


typedef struct s * tPS;

The intent in both cases is to define dPS and tPS to be pointers to structure s.
Which method, if any, is preferred and why?

You might also like