2D Array and CommandLine Argruments
1.
#include<stdio.h>
int main( void )
{
int a[3][2] = {10, 20, 30, 40, 50}, r,c;
for (r = 0; r < 3; r++)
for (c = 0; c < 2; c++)
printf("%d", a[r][c]);
return 0;
}
A. 01020304050
B. 1020304050
C. 5040302010
D. 10203040500
Answer: D
2.
#include<stdio.h>
int main( void )
{
int array[2][3];
array[][]= {{1, 2, 3}, {4, 5, 6}};
printf("%d\n", array[1][0]);
return 0;
}
A. 4
B. Compile time error
C. 1
D. 2
Answer: B
3.
Consider address of mat as 3052555916
#include<stdio.h>
int main( void )
{
1
2D Array and CommandLine Argruments
int mat[2][3] = {1, 2, 3, 4, 4, 3};
printf("%u, %u", mat+1, &mat+1);
return 0;
}
A. 3052555916, 3052555928
B. 3052555916, 3052555940
C. 3052555916, 3052555916
D. 3052555916, 3052555920
Answer: B
4.
#include<stdio.h>
int main( void )
{
int a[2][2] = {10, 20, 30, 40}, r, c;
int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
for(r=0; r<2; r++)
{
for(c=0; c<2; c++)
{
printf(" %d %d %d %d \n", *(*(p+r)+c),
*(*(c+p)+r),
*(*(r+p)+c),
*(*(p+c)+r));
}
}
return 0;
}
A. 10,10,10,10
20,20,20,20
20,20,20,20
30,30,30,30
B. 10,10,10,10
30,30,30,30
20,20,20,20
20,20,20,20
2
2D Array and CommandLine Argruments
C. 30,30,30,30
20,20,20,20
20,20,20,20
10,10,10,10
D. 20,20,20,20
10,10,10,10
20,20,20,20
30,30,30,30
Answer: A
5.
#include<stdio.h>
void fun(int **pp);
int main(void)
{
int arr[3][4]={{1,2,3,4},{4,3,2,8},{7,8,9,0}};
int *ptr=NULL;
ptr = &arr[0][0];
fun(&ptr);
return 0;
}
void fun(int **pp)
{
printf("%d", **pp);
return;
}
A. 1
B. 2
C. 3
D. 4
Answer: A
6.
#include<stdio.h>
int main(void)
3
2D Array and CommandLine Argruments
{
int a[][4] = {{1, 2},{4, 3, 2},{1, 3, 5, 6},{7}};
printf("%d",sizeof(a)/sizeof(a[1][2]));
return 0;
}
A. 64
B. 16
C. 10
D. Complile time error
Answer: B
7.
#include<stdio.h>
int main(void)
{
char arr[3][9] = {"SunBeam", "Pune", "Karad"};
printf("%c - %s",**arr, *arr);
return 0;
}
A. P - Pune
B. S - garbage value
C. S - Sunbeam
D. K - Karad
Answer: C
8.
#include<stdio.h>
int main(void)
{
char str[4][20]={"PG-DAC","PG-DESD","PG-DMC",
"PG-DBDA","PreCat"};
char *p=(char *)str[3];
printf("%s",str[ ++p + str]);
return 0;
}
4
2D Array and CommandLine Argruments
A. Compile time error
B. PG-DBDA
C. PG-DAC
D. PreCat
Answer: A
9.
#include<stdio.h>
int main(void)
{
char str[4][10]={"PG-DAC","PG-DESD","PG-DMC",
"PG-DBDA","PreCat"};
char *p=(char *)str[0];
printf("%s-%c", (p+3)+*(p+1)-p[1],
*(p+3)+*(p+1)-p[1]);
return 0;
}
A. PG-DAC P
B. Compiler Error
C. DAC D
D. NULL 0
Answer: C
10.
#include<stdio.h>
int main(void)
{
char str[5][100]={"PG-DAC","PG-DESD","PG-DMC",
"PG-DBDA","PreCat"};
printf("%d %d %d", sizeof(str),sizeof(str[1]),
sizeof(str[1][1]));
return 0;
}
A. 500 100 1
B. 5 100 1
5
2D Array and CommandLine Argruments
C. 20 100 1
D. 34 100 1
Answer: A
11.
#include<stdio.h>
int main(void)
{
char *str=NULL;
str = "%s";
printf(str, "Sunbeam\n");
return 0;
}
A. %s
B. Compiler Error
C. %s “Sunbeam\n”
D. Sunbeam
Answer: D
12.
#include<stdio.h>
int main(int argc, char *argv[], char *env[])
{
int i;
for(i=1; i<argc; i++)
printf("envp[%d] %s\n",i, env[i]);
return 0;
}
A. command-line arguments list
B. environment variables list
C. count of arguments
D. No output
Answer: D
6
2D Array and CommandLine Argruments
13.
#include<stdio.h>
int main(int argc, char *argv[], char *env[])
{
while (*argv != NULL)
printf("%s\n", *(argv++));
return 0;
}
A. Segmentation fault
B. It will give name of executable file name
C. Compiler dependent
D. No of above
Answer: B
[Link] following program having name cmdline is run from
the command line as
"./[Link] Aptitude English C DS OPPS Networking
Operating System" then what would be the output?
#include<stdio.h>
int main(int argc, char *argv[], char *env[])
{
int i;
for(i=0; i<argc; i++)
printf("%c", argv[i][0]);
return 0;
}
A. /AECDONOS
B. .AECDONOS
C. .AECDONO
D. AECDONOS
Answer: B
7
2D Array and CommandLine Argruments
15.
#include<stdio.h>
int main(int argc, char *argv[], char *env[])
{
printf("%s\n", argv[argc]);
return 0;
}
A. NULL
B. Exit value -1 (run time error)
C. Depends on compiler
D. File Name
Answer: B
16.
If following program having name cmdline is run from
the command line as
"./[Link] August Feb June July" then what would be
the output?
#include<stdio.h>
int main(int argc, char *argv[], char *env[])
{
printf("%c", **++argv);
return 0;
}
A. u
B. March
C. A
D. /
Answer: C