Storage Classes and Type Qualifiers
Question 1
WRONG
|
Which of the following is not a storage class specifier in C?
auto
| |
register
| |
static
| |
extern
| |
volatile
| |
typedef
|
Discuss it
Question 1 Explanation:
volatile is not a storage class specifier. volatile and const are type qualifiers.
Question 4
CORRECT
|
#include <stdio.h> int main() { int x = 5; int * const ptr = &x; ++(*ptr); printf ( "%d" , x); return 0; } |
Compiler Error
| |
Runtime Error
| |
6
| |
5
|
Discuss it
Question 4 Explanation:
See following declarations to know the difference between constant pointer and a pointer to a constant. int * const ptr —> ptr is constant pointer. You can change the value at the location pointed by pointer p, but you can not change p to point to other location. int const * ptr —> ptr is a pointer to a constant. You can change ptr to point other variable. But you cannot change the value pointed by ptr. Therefore above program works well because we have a constant pointer and we are not changing ptr to point to any other location. We are only icrementing value pointed by ptr.
Question 5
WRONG
|
#include <stdio.h> int main() { int x = 5; int const * ptr = &x; ++(*ptr); printf ( "%d" , x); return 0; } |
Compiler Error
| |
Runtime Error
| |
6
| |
5
|
Discuss it
Question 5 Explanation:
See following declarations to know the difference between constant pointer and a pointer to a constant. int * const ptr —> ptr is constant pointer. You can change the value at the location pointed by pointer p, but you can not change p to point to other location. int const * ptr —> ptr is a pointer to a constant. You can change ptr to point other variable. But you cannot change the value pointed by ptr. In the above program, ptr is a pointer to a constant. So the value pointed cannot be changed.
askjdkjash