NEW AND EXCLUSIVE : GO TO THE ONLINE TEST PAGE AND TEST YOURSELF THROUGH EXAMINATION
Showing posts with label Questions and Answers. Show all posts
Showing posts with label Questions and Answers. Show all posts

Find Out the Output of the C-codes

Friends here is five C-questions involving Switch Case.
Lets solve these......
Q.1
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
int check=2;
switch(check){
case 1: printf("D.W.Steyn");
case 2: printf(" M.G.Johnson");
case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
}
}


Q.2
What will be output when you will execute following c code?


#include
<stdio.h> 
#define L 10
void main(){
auto money=10;
switch(money,money*2){
case L: printf("Willian");
break;
case L*2:printf("Warren");
break;
case L*3:printf("Carlos");
break;
default: printf("Lawrence");
case L*4:printf("Inqvar");
break;
}
}

Q.3
What will be output when you will execute following c code?

#include
<stdio.h> 
void main(){
int const X=0;
switch(5/4/3){
case X: printf("Clinton");
break;
case X+1:printf("Gandhi");
break;
case X+2:printf("Gates");
break;
default: printf("Brown");
}
}

Q.4
What will be output when you will execute following c code?


#include
<stdio.h> 
enum actor{
SeanPenn=5,
AlPacino=-2,
GaryOldman,
EdNorton
};
void main(){
enum actor a=0;
switch(a){
case SeanPenn: printf("Kevin Spacey");
break;
case AlPacino: printf("Paul Giamatti");
break;
case GaryOldman:printf("Donald Shuterland");
break;
case EdNorton: printf("Johnny Depp");
}
}

Q.5
What will be output when you will execute following c code?


#include
<stdio.h> 
void main(){
switch(*(1+"AB" "CD"+1)){
case 'A':printf("Pulp Fiction");
break;
case 'B':printf("12 Angry Man");
break;
case 'C':printf("Casabance");
break;
case 'D':printf("Blood Diamond");
}

}


Read More!!

What will be the Output Of the Following C-codes?

Q.1
Which of the following statements are correct about an array?

a:The array int num[26]; can store 26 elements.
b:The expression num[1] designates the very first element in the array.
c:It is necessary to initialize the array at the time of declaration.
d:The declaration num[SIZE] is allowed if SIZE is a macro.


Q.2
If char=1, int=4, and float=4 bytes size, What will be the output of the program ?

#include<stdio.h>


int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}

Q.3
What will be the output of the program ?

#include<stdio.h>

int main()
{
char str[] = "Nagpur";
str[0]='K';
printf("%s, ", str);
str = "Kanpur";
printf("%s", str+1);
return 0;
}


Read More!!

What will be the Output Of the Following C-codes?

Q.1
Point out the error, if any in the program.

#include<stdio.h>
int main()
{
int P = 10;
switch(P)
{
case 10:
printf("Case 1");

case 20:
printf("Case 2");
break;

case P:
printf("Case 2");
break;
}
return 0;
}

Q.2
What will be the output of the program?


#include<stdio.h>
int main()
{
int i=2;
printf("%d, %d\n", ++i, ++i);
return 0;
}



Q.3
 In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators



A.true
B.false


Read More!!

What will be the Output Of the Following C-codes?

Q.1
How many times the program will print "TheNextLevel" ?

#include <stdio.h>
int main()
{
printf("TheNextLevel");
main();
return 0;
}


Q.2
How many times the while loop will get executed if a short int is 2 byte wide?


#include<stdio.h>

int main()
{
int j=1;
while(j <= 255) 

 { 
 printf("%c %d\n", j, j); 
 j++; 
 } 
 return 0; 



 Q.3 Which of the following errors would be reported by the compiler on compiling the program given below? 

 #include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");

case 2:
printf("Second");

case 3 + 2:
printf("Third");

case 5:
printf("Final");
break;

}
return 0;
}


Read More!!

What will be the Output Of the Following C-codes?

Q.1

#include<stdio.h>
int main(){
volatile int a=11;
printf("%d",a);
return 0;
}


Choose all that apply:
(A) 11
(B) Garbage
(C) -2
(D) We cannot predict
(E) Compilation error

Q.2

#include<stdio.h>

const enum Alpha{
X,
Y=5,
Z
}p=10;
int main(){
enum Alpha a,b;
a= X;
b= Z;
printf("%d",a+b-p);
return 0;
}


Choose all that apply:
(A) -4
(B) -5
(C) 10
(D) 11
(E) Error: Cannot modify constant object


Read More!!

What will be the Output Of the Following C-codes?

Q.1

main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}


Q.2

#include<stdio.h>
#include<conio.h>
main()
{
int i;
for(i=1;i<=5;printf("%d\n",i)) i++; 

getch(); 
}

Read More!!

What is Kernel level Threads ?

The identity of a Kernel level thread is known to the OS Kernel. A process creates threads in a way analogues to the create-process call.Let us call this create-thread call.One of the parameters of this call is the start address of thread in the code of creating process.The Karnel creates appropriate data structures for the new thread and assigns it an id.The call




returns with the id of the thread.The process creating the thread can use this id for synchronization purpose.The Kernel data structure for a thread would be a subset of the data structure for a process.A thread control block would be needed analogues to PCB fields which store resource allocation information would not be needed.The scheduler use the thread control block for the purpose of scheduling.The context switching actions are now of two kinds.The kernel would only save and load the CPU state while switching between threads of the same process.It would save and load the process environment if the thread being interrupted and the thread being scheduled to run belong to different processes.

    Kernel level threads can use all the privileges and facilities provided by processes themselves.Thusthey can make system calls to convey this resource and I/O requirements to the OS.

Difference with pure user level threads:

A kernel level thread (KLT) is a thread that the kernel is aware of, i.e. the kernel can decide which KLT will be schedule (assigned ot the CPU). Pure user level threads (PULTs) are not known to the kernel: One or more PULTs may run on top of a KLT and the kernel can only schedule the KLT. The decision which of the PULTs is scheduled is left to the user level scheduler in your application.
There are some tradeoffs between PULTs and KLTs and there are even hybrid models but the following problem remains: The kernel can only schedule KLTs to run on a given CPU. If you have more than one CPU/core then the kernel can schedule two KLTs to run concurrently.
For example you could decompress two JPEGs at the same time in your web browser if you have two cores on your CPU.

Ruby only offers PULTs. What does this mean? This means that you cannot have one Ruby process with two threads running at the same time. You cannot, for example, let a Rails process generate two differently sizted thumbnails of an uploaded image at the same time. You cannot answer more than one request at the same time without stopping the other thread. You cannot do numerical computations on more than one core at the same time.


Read More!!

What will be the Output Of the Following C-codes?

Q.1

#include<stdio.h>
int main(){
char p[]="String";
if(p=="String"){
printf("Pass 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
 else{
printf("Fail 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
return 0;
}





Q.2

func(int a,int b);
void main()
{
int i=7,j=8;
printf("%d\n",func(i,j));
}
func(int a,int b)
{
a=a-b;
b++;
return(b||a+--b);
}

Read More!!

What will be the Output Of the Following C-codes?

Q.1

#include<stdio.h>
int main(){
const int *p;
int a=10;
p=&a;
printf("%d",*p);
return 0;
}

Which one is correct?
(A) 0
(B) 10
(C) Garbage value
(D) Any memory address
(E) Error: Cannot modify const object


Q.2

#include<stdio.h>

int main(){
int a= sizeof(signed) +sizeof(unsigned);
int b=sizeof(const)+sizeof(volatile);
printf("%d",a+++b);
return 0;
}

Which one is correct?
(A) 10
(B) 9
(C) 8
(D) Error: Cannot find size of modifiers
(E) Error: Undefined operator +++


Read More!!

What will be the Output Of the Following C-codes?

Q.1


#include<stdio.h>
int main(){
double num=5.2;
int var=5;

printf("%d\t",sizeof(!num));
printf("%d\t",sizeof(var=15/2));
printf("%d",var);
return 0;
}

Q.2


 #include<stdio.h>

int main(){
printf("%d\t",sizeof(6.5));
printf("%d\t",sizeof(90000));
printf("%d",sizeof('A'));
return 0;
}


Read More!!