QUESTION 6
What is the output of following C code?
struct numbers
{
int x = 2;
int y = 3;
}
int main()
{
struct numbers nums;
nums.x = 110;
nums.y = 100;
printf("%d\n%d", nums.x, nums.y);
return 0;
}
| A. |
Compile-time Error |
|
| B. |
110 100 |
|
| C. |
2 3 |
|
| D. |
Run-time Error |
2 points
QUESTION 7
What is the output of following C code?
typedef struct student
{
char *stud;
}s1;
int main()
{
s1 s;
s.stud = "Amy";
printf("%s", s.stud);
return 0;
}
| A. |
Garbage Value |
|
| B. |
Amy |
|
| C. |
A |
|
| D. |
Compile-time Error |
2 points
QUESTION 8
What is the output of following C code?
struct point
{
int x;
int y;
};
void fun(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5, 6};
fun(p1);
return 0;
}
void fun(struct point p[])
{
printf("%d %d\n", p->x, (*(p+1)).y);
}
| A. |
Compile-time Error |
|
| B. |
1 4 |
|
| C. |
3 5 |
|
| D. |
1 2 |
2 points
QUESTION 9
What is the output of following C code?
struct point
{
int x;
int y;
};
void fun(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5, 6};
fun(p1);
return 0;
}
void fun(struct point p[])
{
printf("%d %d\n", p->x, *(p+1).y);
}
| A. |
Compile-time Error |
|
| B. |
1 4 |
|
| C. |
3 5 |
|
| D. |
1 2 |
2 points
QUESTION 10
What will be the output of the program (CmdLinePrg.c) given below, if it is executed from the command line as follows:
$ gcc CmdLinePrg.c one two three
(OR when Program arguments are set in the IDE as: one two three)?
/* CmdLinePrg.c */
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%c", **++argv);
return 0;
}
| A. |
CmdLinePrg.c one two three |
|
| B. |
CmdLinePrg.c one |
|
| C. |
o |
|
| D. |
one |
Question 6: Compile-time Error Question 7: Amy Question 8: 1 4 Question 9: Compile-time Error Question 10: CmdLinePrg.c one two three
QUESTION 6 What is the output of following C code? struct numbers { int x...
QUESTION 1 In order to print the members of structures in the array, what will be the contents of blanks in the printf statement of the code snippet given below? #include <stdio.h> struct virus { char signature[25]; char status[20]; } v[2] = { "Yankee Doodle", "Deadly", "Dark Avenger", "Killer" } ; void main( ) { for (int i = 0; i < 2; i++) printf( "\n%s %s", _______________ , _____________ ); } A. signature, status B. v.signature,...
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
1.What will be output if you will compile and execute the following c code? struct markst int p:3; int c:3; int m:2; void main) struct marks s=(2,6,5); printf("%d %d %d",s-Ds.c,s.m); 2-6 5 2-6 1 2 21 Compiler error Ans: C Explanation Binary value of 2: 00000010 (Select three two bit) Binary value of 6: 00000110 (Select last three bit) Binary value of 5: 00000101 (Select last two bit) 2.A function that uses variable types is called Overloaded a template function...
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...
What is the output of the following code: void forkexample() { int x = 1; if (fork==0) printf(“ Child has x = %d\n”, ++x); Else printf(“ Parent has x = %d\n”, - - x); } int main () { forkexample(); Return 0; }
int *fun(int *p) { while(*p >= 0) p++; return p; } void main() { I int *a; int v[8]={1,2,3,-4,5,6,7,8); q = fun(); printf("%d", _Missing_1_); printf("%d", -_Missing_2_); } However, part of the code is missing (indicated by). The code is supposed to give the output -46 What can the missing parts be? DS (4 Points) Missing 1: * Missing 2: [2] Missing_1: V[4] Missing 2: [2] Missing 1: *q Missing 2: q[1] Missing 1: *(q+1) Missing 2: *(q+2)
Combine two codes (code 1) to get names with(code 2) to get info: Code 1: #include<unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<dirent.h> #include<stdio.h> #include<stdlib.h> void do_ls(char []); int main(int argc,char *argv[]) { if(argc == 1) do_ls("."); else while(--argc){ printf("%s:\n",*++argv); do_ls(*argv); } } void do_ls(char dirname[]) { DIR *dir_ptr; struct dirent *direntp; if((dir_ptr = opendir(dirname)) == NULL) fprintf(stderr,"ls1:cannot open %s\n",dirname); else { while((direntp = readdir(dir_ptr)) != NULL) printf("%s\n",direntp->d_name); closedir(dir_ptr); } } ____________________________ code 2: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> void show_stat_info(char *,...
24. What will be the output of the following code #include<stdio.h> int main() { char *p; p="%d\n"; p++; p++; printf(p-2, 100); return 0; } a. 100 b. 00 c. 10 d. compiler error e. none of the above 26. What will be the output of the following code #define TRIPPLE(x) (3*x) int x = 4; printf(“triple(%d) = %d \n”,x+1, TRIPPLE(x+1)); a. triple(5) = 12 b. triple(5) = 13 c. triple(4) = 14 d. triple(4) = 15 e. none of the...
QUESTIONS What will be the output of the following C code? 1. #include <stdio.h> int maino int 1 - -3; int k - * % 2; printf(\n", k); Compile time error O-1 Implementation defined