Last active
July 2, 2019 18:55
-
-
Save jagannath-sahoo/fa5690f1269084aaf3f3d79dcbd8cc64 to your computer and use it in GitHub Desktop.
Output Questions of C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| int a[4] = {1, 2, 3, 4}; | |
| int b[4] = {1, 2, 3, 4}; | |
| int n = &b[3] - &a[2]; | |
| printf("%d\n", n); | |
| } | |
| 2) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| void *p; | |
| int a[4] = {1, 2, 3, 8}; | |
| p = &a[3]; | |
| int *ptr = &a[2]; | |
| int n = p - ptr; | |
| printf("%d\n", n); | |
| } | |
| 3) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| int a[4] = {1, 2, 3, 4}; | |
| void *p = &a[1]; | |
| void *ptr = &a[2]; | |
| int n = 1; | |
| n = ptr - p; | |
| printf("%d\n", n); | |
| } | |
| 4) | |
| #include <stdio.h> | |
| void main() | |
| { | |
| int a[3] = {1, 2, 3}; | |
| int *p = a; | |
| int **r = &p; | |
| printf("%p %p", *r, a); | |
| } | |
| 5) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| char *a = {"p", "r", "o", "g", "r", "a", "m"}; | |
| printf("%s", a); | |
| } | |
| 6) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| char *p[1] = {"hello"}; | |
| printf("%s", (p)[0]); | |
| return 0; | |
| } | |
| 7) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| int i = 0, j = 1; | |
| int *a[] = {&i, &j}; | |
| printf("%d", (*a)[1]); | |
| return 0; | |
| } | |
| 8) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| char *a[2] = {"hello", "hi"}; | |
| printf("%d", sizeof(a)); | |
| return 0; | |
| } | |
| 9) | |
| #include <stdio.h> | |
| void f(int (*x)(int)); | |
| int myfoo(int); | |
| int (*fooptr)(int); | |
| int ((*foo(int)))(int); | |
| int main() | |
| { | |
| fooptr = foo(0); | |
| fooptr(10); | |
| } | |
| int ((*foo(int i)))(int) | |
| { | |
| return myfoo; | |
| } | |
| int myfoo(int i) | |
| { | |
| printf("%d\n", i + 1); | |
| } | |
| 10) | |
| #include <stdio.h> | |
| int main() | |
| { | |
| int *((*x)())[2]; | |
| x(); | |
| printf("after x\n"); | |
| } | |
| int *((*x)())[2] | |
| { | |
| int **str; | |
| str = (int*)malloc(sizeof(int)* 2); | |
| return str; | |
| } | |
| ================================================== | |
| OS | |
| ================================================== | |
| 1) | |
| 11. The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0. | |
| Process P0 | |
| while(true) | |
| { | |
| wait(S0); | |
| print '0'; | |
| release(S1); | |
| release(S2); | |
| } | |
| Process P1 | |
| wait(S1); | |
| release(S0); | |
| Process P2 | |
| wait(S2); | |
| release(S0); | |
| How many times will P0 print ‘0’ ? | |
| a) At least twice | |
| b) Exactly twice | |
| c) Exactly thrice | |
| d) Exactly once |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment