Sunday 18 April 2021

Weekly Test - 18 April 2021 (C and C++)

 

                    Weekly Test - 18 April 2021 (C and C++)






ALL THE BEST!!!

Saturday 17 April 2021

OS Thread Assignment S P SHARMA CLASSES

 

1.)    A process can be ___________

A).    Single threaded

B).    Multithreaded

C).    Both single threaded and multithreaded

D).   None of the mentioned

2.)    Which one of the following is not shared by threads?

A).    Program counter

B).    Stack

C).    Both program counter and stack

D).   None of the mentioned

3.)    The time required to create a new thread in an existing process is ___________

A).    Greater than the time required to create a new process

B).    Less than the time required to create a new process

C).    Equal to the time required to create a new process

D).   None of the mentioned

4.)    Termination of the process terminates ___________

A).    First thread of the process

B).    First two threads of the process

C).    All threads within the process

D).   No thread within the process

5.)    Which one of the following is not a valid state of a thread?

A).    Running

B).    Parsing

C).    Ready

D).   Blocked

6.)    Thread synchronization is required because ___________

A).    All threads of a process share the same address space

B).    All threads of a process share the same global variables

C).    All threads of a process can share the same files

D).   All of the mentioned

7.)    A thread is also called ___________

A).    Light Weight Process(LWP)

B).    Heavy Weight Process(HWP)

C).    Process

D).   None of the mentioned

8.)    A thread shares its resources(like data section, code section, open files, signals) with ___________

A).    Other process similar to the one that the thread belongs to

B).    Other threads that belong to similar processes

C).    Other threads that belong to the same process

D).   All of the mentioned

9.)     A heavy weight process ___________

A).    Has multiple threads of execution

B).    Has a single thread of execution

C).    Can have multiple or a single thread for execution

D).   None of the mentioned

10.) A process having multiple threads of control implies ___________

A).    It can do more than one task at a specific time

B).    It can do only one task at a time, but much faster

C).    It has to use only one thread per process

D).   None of the mentioned

11.) Multithreading an interactive program will increase responsiveness to the user by ___________

A).    Continuing to run even if a part of it is blocked

B).    Waiting for one part to finish before the other begins

C).    Asking the user to decide the order of multithreading

D).   None of the mentioned

12.) Resource sharing helps ___________

A).    Share the memory and resources of the process to which the threads belong

B).    An application have several different threads of activity all within the same address space

C).    Reduce the address space that a process could potentially use

D).   All of the mentioned

13.) Multithreading on a multi – CPU machine ___________

A).    Decreases concurrency

B).    Increases concurrency

C).    Doesn’t affect the concurrency

D).   Can increase or decrease the concurrency

14.) The kernel is _______ of user threads.

A).    A part of

B).    The creator of

C).    Unaware of

D).   Aware of

15.) If a kernel thread performs a blocking system call, ____________

A).    The kernel can schedule another thread in the application for execution

B).    The kernel cannot schedule another thread in the same application for execution

C).    The kernel must schedule another thread of a different application for execution

D).   The kernel must schedule another thread of the same application on a different processor

16.) If the kernel is single threaded, then any user level thread performing a blocking system call will ___________

A).    Cause the entire process to run along with the other threads

B).    Cause the thread to block with the other threads running

C).    Cause the entire process to block even if the other threads are available to run

D).   None of the mentioned

17.) Which of the following is FALSE?

A).    Context switch time is longer for kernel level threads than for user level threads

B).    User level threads do not need any hardware support

C).    Related kernel level threads can be scheduled on different processors in a multiprocessor system

D).   Blocking one kernel level thread blocks all other related threads





Answer:


1.      C

2.      C

3.      B

4.      C

5.      B

6.      D

7.      A

8.      C

9.      B

10.   A

11.   A

12.   D

13.   B

14.   C

15.   A

16.   C

17.   D

 

 

Tuesday 13 April 2021

Storage classes in C and C++ - 3

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

int a=5;

void show();

int main()

{

clrscr();

a=10;

extern int a;      //variable already declare in global scope.

cout<<a;

show();

a=20;

cout<<endl<<a;

show();

cout<<endl<<a;

getch();

return 0;

}


int a;

void show()

{

cout<<endl<<a;

a=50;

}

Storage class in C and C++ - 2

 #include<stdio.h>

#include<conio.h>

//#include<iostream.h>

int main()

{

//clrscr();

register int a=8;

//int *p=&a;

//cout<<&a<<endl;

//cout<<p<<endl;

//cout<<*p;

//printf("%u\n%d",p,*p);

printf("%u",&a);

getch();

}

Storage class in C and C++ - 1

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

void show()

{

static int a=5;

cout<<a<<endl;

a++;

}


int main()

{

clrscr();

//int a=5;

show();

show();

show();

/*{

int a=10;

cout<<a<<endl;

}

cout<<a;

*/

getch();

return 0;

}

Enum in C and C++ - 2

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

enum week{sun=3,mon,tue,wed=-2,thu,fri,sat}d;

int main()

{

clrscr();

d=fri;

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

enum week day;

day =mon;

cout<<day<<endl;

week d1;

d1='k';

d1=9;

d1=5.7;

cout<<d1;

getch();

return 0;

}

Enum in C and C++ - 1

 #include<stdio.h>

#include<conio.h>

#include<iostream.h>

int main()

{

clrscr();

enum week{sun=3,mon,tue,wed=-2,thu,fri,sat};

week day;

day=fri;

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

day =mon;

cout<<day<<endl;


getch();

return 0;

}

Union in C and C++

 #include<iostream.h>

#include<conio.h>

union Book

{

char code;

int pages;

float price;

};

int main()

{

clrscr();

Book b;

b.code='A';

b.pages=400;

b.price=150;

cout<<b.code<<endl;

//b.pages=500;

cout<<b.pages<<endl;

//b.price=300;

cout<<b.price<<endl;

cout<<sizeof(b);

int *p=(int*)100;


getch();

return 0;

}

Structure in C and C++ - 4

 #include<iostream.h>

#include<conio.h>

struct Book

{

char code;

int pages;

float price;

void show()

{

Book b[3];

cout<<sizeof(b)<<endl;

int i;

for(i=0;i<3;i++)

{

cout<<"Enter book code, pages and price\n";

cin>>b[i].code>>b[i].pages>>b[i].price;

}

for(i=0;i<3;i++)

cout<<"Code="<<b[i].code<<" Pages="<<b[i].pages<<" Price="<<b[i].price<<endl;

}

};


int main()

{

clrscr();

Book b;

b.show();

getch();

return 0;


}

Structure in C and C++ - 3

 #include<iostream.h>

#include<conio.h>

struct Book

{

char code;

int pages;

float price;

};

int main()

{

clrscr();

Book b[3];

cout<<sizeof(b)<<endl;

int i;

for(i=0;i<3;i++)

{

cout<<"Enter book code, pages and price\n";

cin>>b[i].code>>b[i].pages>>b[i].price;

}

for(i=0;i<3;i++)

cout<<"Code="<<b[i].code<<" Pages="<<b[i].pages<<" Price="<<b[i].price<<endl;

getch();

return 0;


}