Você está na página 1de 9

Try It Yourself C:

1.

What is the output of the below program? int main() { int i = -1, j = -1 , k = 0, l = 2, m; m=i++ && j++ && k++ || l++; printf("%d %d %d %d %d", i, j, k, l, m); }

2.

What is the output of the below program? int main() { int i = 5; printf(" %d ", i=++i == 6); }

3.

What is the output of the below program? int main() { unsigned int i; i = (64 >> (2+1-2)) & (~ (1<<2)); printf (" %d\n ", i); return 0; }

4.

What is the output of the below program? int main() { int i =0, j=0; if(i && j++) printf(" %d %d" , i++, j); printf(" %d %d , i, j); }

5.

What is the output of the below program?

int main() { int i=5; printf(" %d %d %d %d %d %d ", i++, i--, ++i, --i, i); } 6. In C all functions except main() can be called recursively? a)True b)False

7. A function may have any number of return statements and each returning different values? a)True b)False

8. Will the statement below show an error, when f1 and f2 are two different functions in the same program? int f1(int a, int b) { return ( f2(20) ); } int f2(int x) { return(x*x); }

9. What is the output of the program? main() { int a=5; void f(); a=f(); printf("%d",a); return 0; }

10. What is the output? #include<stdio.h> int f(int); int main() {

int a, b; a = f(123); b = f(123); printf("%d, %d\n", a, b); return 0; } int f(int n) { int s, d; if(n!=0) { d = n%10; n = n/10; s = d+f(n); } else return 0; return s; }

11. Find the output #include<stdio.h> int f(int); int main() { int k=35; k = f(k=f(k=f(k))); printf("k=%d\n", k); return 0; } int f(int k) { k++; return k; }

12. Find the output of the program: int f(int(*)()); int main()

{ f(main); printf("Hi\n"); return 0; } int f(int (*p)()) { printf("Hello "); return 0; }

13. Find the output of the program: int main() { int x = 10, y = 20; if(!(!x) && x) printf("x = %d\n", x); else printf("y = %d\n", y); return 0; }

14. Point out the error: #include<stdio.h> int main() { int a = 10; switch(a) { } printf("This is c program."); return 0; } 15. What is the output of the following code? #include <stdio.h> void main() { int a=5,b=10,c=1; if (a&&b>c) printf(Hello World!); else

break; }

16.What is the output of the following code? #include <stdio.h> void main() { if (sizeof(void)) printf(Hello World!); else printf(Bye World!); } 17.What is the output of the following code? #include<stdio.h> void main() { static int i; for (;;) if (i+++Apple) printf(Banana); else break; } 18. What is the output of the following code? #include<stdio.h> void main() { char c=256; char *ptr=Hello; if (c==0) while (!c) if (*ptr++) printf(%+u,c); else break; } 19. What is the output of the following code?(an easy one) #include<stdio.h> void main()

{ int a=2; if (a--,--a,a) printf(Hello World!); else printf(Bye world!); }

20. What is the output of the program? #include<stdio.h> void main() { int n=0; switch(n) { case 0: do{ n=6; case 7: case 6: case 5: case 4: case 3: case 2: case 1: }while(--n>0); n=8; case 8: printf("one"); } printf("7"); printf("6"); printf("5"); printf("4"); printf("3"); printf("2"); printf("1");

JAVA:

1. A number of threads of the same priority have relinquished the lock on a monitor and are in a waiting state after having called the wait() method of the object. A new thread enters the monitor and calls the notifyAll() method of the monitor. Which of these threads will be the first one to resume? 2. How do you think the start() method of Thread class is implemented if Java depends on native threads? 3. What will the code print? Can you justify why it prints that? class A extends Thread { String[] sa; public A(String[] sa) {this.sa = sa;} public void run() { synchronized (sa) { System.out.print(sa[0] + sa[1] + sa[2]);} }} class B { private static String[] sa = new String[]{"X","Y","Z"}; public static void main (String[] args) { synchronized (sa) { Thread t1 = new A(sa); t1.start(); sa[0] = "A"; sa[1] = "B"; sa[2] = "C"; }}} 4. Given the code below: public class Test extends Thread{ String msg = "default" ; public Test(String s){ msg = s; } public void run(){ System.out.println(msg); } public static void main(String args[]){ new Test("String1").start(); new Test("String2").start();

System.out.println("end"); } } Can you guarantee that this code will always print String1 and String2. Did you have to make any changes to the code to ensure this? 5. This code does not run into infinite loop? Why? class A extends Thread { public void run() { while(true){ try{ Thread.sleep(10);}catch (InterruptedException ie){} } } public static void main(String[] args) {A a1 = new A(); a1.setDaemon(true); long startTime = System.currentTimeMillis(); a1.start(); System.out.print(System.currentTimeMillis() - startTime); } }

6. Why should a class implement Serializable if the interface has no methods? 7. Why does java differentiate between two different types of streams? 8. How many serialized objects can you save in a file? Should they all be of same type? 9. Suppose you did not have Scanner class. How will you read an integer and a string using Stream classes? 10. Should you allow serialization on all objects? Which java objects can you not serialize?

Did You Know??? "The Dirty Dozen" was the term used to refer to the group of 12 engineers who designed the IBM PC The first MS-DOS virus released world wide was called Brain which is a boot-sector virus.It was written by the Alvi brothers, Basit Farooq Alvi and Amjad Farooq Alvi .Apparently they had written the program to prevent their research work from piracy . Leo Tolstoy took sixteen years to write "War & Peace".

A small piece of software that adds features to a larger piece of software is called a plug-in. They are used by Internet browsers to increase the program's functions Microsoft Windows tutorials is also referred to as 'Crash Course' The first mouse was designed by Douglas Englebart and it was made of wood. It was then known as X-Y Position Indicator for a Display System. Marissa Meyer was Googles first female engineer and worked for over 13 yrs with Google. She was recently appointed as the CEO of Yahoo!

Thought For The Week: Be not afraid of going slowly; be only afraid of standing still." -Chinese Proverb

Você também pode gostar