0% found this document useful (0 votes)
4 views11 pages

Questions

The document contains a series of programming exercises and questions related to C programming concepts such as number system conversions, data types, memory management, and various operations on arrays and structures. It also touches on topics like pointer arithmetic, file operations, and bitwise operations, along with specific code snippets and expected outputs. Additionally, it includes a list of topics for further study in advanced C programming and operating systems.

Uploaded by

sstories569
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)
4 views11 pages

Questions

The document contains a series of programming exercises and questions related to C programming concepts such as number system conversions, data types, memory management, and various operations on arrays and structures. It also touches on topics like pointer arithmetic, file operations, and bitwise operations, along with specific code snippets and expected outputs. Additionally, it includes a list of topics for further study in advanced C programming and operating systems.

Uploaded by

sstories569
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
You are on page 1/ 11

1.

Conversion of number systems

Hexadecimal Numbers Decimal Numbers Octal Numbers Binary Numbers

241

2.

Define a binary number 15:int a =

Define an octal number 15:int b =

Define a hexadecimal number 15:int c =

3、

char str1[] = "";

char str2[] = {};

printf("%d %d\n",sizeof(str1),sizeof(str2));

char array1[]={"I am a student”} strlen(array1) = ____ sizeof(array1) = ____

char array2[]="I am a student"; strlen(array2) = ____ sizeof(array2) = _____

char *array3 ="I am a student"; sizeof(array3) = _____ strlen(array3) = _____

char *array4[6]={"12345","23456", "34567"}; sizeof(array4) = ______

4、

int a = 3, b = 2, c= 1;

if(a>b)

a=c;

else;

c=b;

if(a=b)

b=c;

else

b=3;

printf("a = %d, b = %d, c = %d.\n", a, b, c);


____,____,____、

5.

unsigned char a = 200, b = 100, c = 0, d = 0;

c = a + b;

d = b - a;

printf("%d, %d, %d, %d.\n", a + b, c, b - a, d);

___,____,____

6、

int array1[10] = {1, 2, 3, 4, 5}; //Suppose the address of array1

is 0x8000

printf("%p, %p.\n", array1 + 1, &array1 + 1);

____,___,___

7.

int x = 10;

test_fun()

x++;

return;

void main()

int x = 3;

test_fun();

x--;

printf("x = %d.\n",x);

return;
}

x=

8、a/b/c/d are all integer variables, d = (c = (a = 11, b = 22)) == 11;

c = ___ d = ____

9、

char array2[2][5]={"abcde","1234"};

char (*p2)[5] = array2;

printf("%s, %s, %s.\n", *p2, p2 + 1, *p2 + 1);

___ , ___, ___ .

10、

char *array3[3]={"adh","bei", "cfh"};

char **p3 = array3;

printf("%s, %s, %c, %c.\n", *p3 + 2, *(p3 + 2), **p3 + 2, **(p3 +

2));

___ , ___, ___ , ___

11、

char str1[20] = "abcd", str2[20] = "ABCD", str3[20]="xyz";

strcpy(str3 + 2, strcat(str1 + 2, str2 + 1));

printf("%s.\n",str3);

12、Spaces should be represented

printf("%010.2f, %o, %8.3s, %x, %-05u %+05u.\n", 10.125, 9,

"hello", 21, 39, 36);

___ , ___, ___ , ___ , ___ , ___ ,

13. unsigned char a = 0, b = 0, c = 0, d = 0;

a = 7 ^ 3;

b = 3 <<2;

c = ~1;

d = ~(a >> 1);


printf("%u, %u, %u, %u, %u, %u.\n", a, b, c, a & b, a || b, d);

___ , ___, ___ , ___ , ___ , ___ ,

14、Given following definitions in C program :

#define S(a,b) a*b

int area=S(3+1,3+4);

what’s the value of variable area______.

15、If variable a is int type,and we execute statement:

a=‘A'+1.6; which following statement is correct(______)

A. variable a’s value is char ‘c’

B. variable a’s type is float

C. float type variable can not add with char type variable

D. variable a’s value is char ‘A’ ASCII value add 1

E. none of above is correct

16、

void main(void)

char*s = "hello";

char ch='a';

printf( "sizeof('a') = %u\n", sizeof( 'a'));

printf( "sizeof(*s+0) = %u\n", sizeof(*s+ 0));

printf( "sizeof(*s) = %u\n", sizeof(*s));

printf( "sizeof(s) = %u\n", sizeof(s));

return;

sizeof('a') =______ sizeof(*s+0) =______ sizeof(*s) =______

sizeof(s) = ______

17、 Describe the meaning of const in the following three

statements
char * const p; ______

char const * p; ______

const char *p; ______

18、

int x = 3, y = 2, z = 3;

z = x < y ? !x : !((x = 2) || (x = 3)) ? (x = 1): (y = 2);

x =______, y =______, z =______.

19、

struct Test1

int b;

double c;

long d;

}data, *p;

sizeof(data) =______, mode of accessing domain b =______

20、 Define the following using variable a:

a.An array of 10 pointers that point to an integer

b.A pointer to an array of 10 integers

c.A pointer to a function that takes an integer parameter and

returns an integer

d.An array of 10 pointers that point to a function that takes an

integer parameter and returns an integer

a. ______, b. ______, c. ______, d. ______.

21、

unsigned char *p1;

unsigned long *p2;

p1 = (unsigned char *)0x8000;

p2 = (unsigned long *)0x8000;

p1 + 5 =______
p2 + 5 =______

22、

void main(void)

int a[5]={1,2,3,4,5};

int * ptr=(int*)(&a+1);

printf(“%d,%d”,*(a+1),*(ptr-1));

return;

*(a+1) ______ , *(ptr-1) ______

23.

Differences between file operation a and a+

Differences between file operation w and w+

24.

int main(void)

int array[2][3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 13,14,15,16,17,18,19,20,21,22,23,24 };

printf("%d %d %d\n",array[0][5][1], array[1][2][1], array[2][2][2]);

return 0;

____,___,___

25.

int main(void) {

char *str1 = "A";

char *str2 = "ABC";

char *str3 = "ABCDEFGH";

printf("%5s,%.5s,%5.6s\n",str1,str1,str1);
printf("%5s,%.5s,% 5.6s\n",str2,str2,str2);

printf("%5s,%.5s,%5.6s\n",str3,str3,str3);

return 0;

26. 32 bits and 64 bits separately answer

typedef struct data

short a;

char b;

long long c;

char d;

}data;

int main(void) {

printf("%d\n",sizeof(data));

return 0;

_____

27. for 32 bits and 64 bits separately answer.

struct AA{

int a;

char b;

short c;

char d;

};

struct BB{
struct AA a;

char b;

char c;

int d;

};

#pragma pack(2)

struct CC{

char a;

struct BB b;

char c;

int d;

};

#pragma pack()

#pragma pack(1)

struct DD {

char a;

short b;

struct CC c;

char d;

};

int main()

{ struct AA w;

struct BB x;

struct CC y;

struct DD z;

printf("%d %d %d %d\n",sizeof(w), sizeof(x), sizeof(y), sizeof(z));

}
____,____,____,____

28.

printf(“%d %d %d %d %d\n”, \ ~-1, !-1, -1 & 1, -1 && 1, -1 ^ 1 \ );

____,____,____,____,___.

29.

int a[3][4] = {0};

printf("%p %p\n",a[0][0], a[0][0]+1);

printf("%p %p\n", &a[0][0], &a[0][0]+1);

printf("%p %p\n", a[0], a[0]+1);

What are their data types?

Let, address of a = 0x1000

30.

char array2d[2][5] = {"12345","abcd"};

char (*p2)[5] = array2d;

char **p3 = (char **)((char *)(p2+1)+3);

printf("%s %s %s %c\n",*p2,p2+1,*p2+1,*p3);

____,____,___,____

31.

char *array[3] = {"12345","34567","56789"};

char **p1 = array;

printf("%d\n", sizeof(array));

printf("%s %s %c %c\n",*p1+2,*(p1+2),**p1+2,**(p1+2));

32. int aa[2][5] = {1,2,3,4,5,6,7,8,9,10};


int *p1 = (int *)(&aa+1);

int *p2 = (int *)(aa+1);

int *p3 = (int *)(aa[0]+1);

int *p4 = (int *)(&aa[0]+1);

int *p5 = (int *)(&aa[0][0]+1);

int *p6 = (int *)(&aa)+1;

printf("%p %p %p %p %p %p\n",p1, p2, p3, p4, p5, p6);

Let, address of aa = 0x1000

_____,_____,_____,____,____,____

33.

enum Weekday {

Sunday,

Monday,

Tuesday,

Wednesday,

Thursday = 10,

Friday,

Saturday

};

int main() {

enum Weekday today = Wednesday;

printf(" %d\n", today);

printf(" %u bytes\n", sizeof(enum Weekday));

printf(" %u bytes\n", sizeof(today));

today = Saturday;

printf(" %d\n", today);


Topics:

 define , typedef (difference)


 little endian & big-endian (application)
 byte alignment
 sizeof, strlen ,strcpy,strcat.strnlen,strncat
 integer promotion
 memory management (stack ,heap,rodata,data section,bss)
 sign extension & zero extension
 logical shift ,arithmetic shift
 Little endian , big endian
 Pointer ,pointer type er conversion, pointer arithmetic(32 bit/64 bit)
 ternary operator
 struct size , packing & padding (32 bit/64 bit)
 enum
 bit field
 1's complement 2's complement (advantage / disadvantage)
 single /doubly linked list, create,delete,insert
 postfix to prefix vice versa
 bitwise operation+
 binary tree ,binary search

May be it can be helpful.

Advanced C Programming - Introduction (+5 Tricky Code) | Sanfoundry - YouTube

OS - process ,thead, synchronization ,lock ,memory management ,fragmentation,deadlock ,critical


section

Network - ip class ,subnet mask ,gateway

You might also like