prog_name one two three four
will have the below behaviour ( select the right option )
A) program has compilation errors
B) Program prints "three"
C) program prints "hree"
D) program prints "three four"
59) Which of the following statements are valid regarding "static" variables in C?
A) Have global scope and lifetime till the end of the program.
B) Have block scope and lifetime till the end of the block.
C) Have block scope and lifetime till the end of the program.
D) Have global scope and lifetime till the end of the block
60) What is the output of the code segment below?
char c;
int i = 0 ;
for( c = 'A' + i ; c < 'Z' ; c += 2,i++ )
{
printf("%c", c);
}
A) ADHMS (skips 2,3,4,5 characters in between A and Z)
B) ACEGIKMOQSUWY (skips one char in between A and Z)
C) ABCDEFGHI...Y (prints all characters from A to Y)
D) Program does not compile.
61) Select the correct statements in relation to the "realloc" function
A) The realloc tries to allocate new memory which starts at the old memory and if it cannot find sequential memory extending the old memory, realloc will fail...
B) After the call to realloc, we need to copy the data from the old pointer
C) Based on where the new memory is allocated, the realloc function takes care
Of copying the data into the new location, but the caller needs to free the
D) Both data copy and freeing of old memory whenever required, is taken care
62) In the declaration char c_arr[100] = "CMCLIMITED" ; , c_arr is :
A) a constant pointer to character.
B) non-const pointer to a character constant.
C) non-const pointer to character.
D) a constant pointer to constant character.
63) Looking at the code lines below, select the correct statement(s) below:
Line 1 char *c_ptr;
Line 2 char a_arr[100];
Line 3 c_ptr = (char *) malloc (10*sizeof (int));
Line 4 c_ptr = c_arr;
Line 5 free (c_ptr);
A) Line 3 has compilation error: it uses sizeof (int) instead of sizeof (char)
B) Line 4 has an error as we cannot assign an array pointer to a normal pointer.
C) Line 5 has a compilation error.
D) Line 5 has undefined behavior.
64) Which of the following functions deal with binary output into a file?
A) fprintf()
B) fputs();
C) fwrite();
D) All of the above.
65) Which of the following are valid file operation functions in C?
A) fseek()
B) ftell()
C) rewind()
D) All of the above.
66) Assuming all headers included, indicate the behavior of the below program:
Int arr[10] = {1,2,3,4,5,6,7,8,9,10};
Int I = 0;
while( I < 10 )
{
printf(“%d\n”, *(arr++));
}
A) prints numbers from 1 to 10
B) prints numbers from 1 to 9
C) prints ‘1’ ten times.
D) program has compilation errors.
67) Given a structure typedef struct { char x; int y, int z} mystruct;
sizeof(mystruct) will return
A) 5 -- Always
B) 6 -- Some times
C) 8 -- Based on Memory size
D) None of the above
68) char *p = (char*) malloc(2000000*2/10+4);
int length = strlen(p);
Output of the above program:
A) 400004
B) 200002
C) NULL
D) None of the above
69) A program is written in “C” language , and an executable is made by compiling it on unix/linux environment. Can we run the executable on windows operating system.
A) Yes, Always
B) Only on vista operating system
C) Never
D) If we change extension to .exe, it will run
70) Main difference of a struct in C and C++
A) In C members are private, c++ members are virtual
B) In C members are public, c++ members are private
C) In C members are virtual, c++ members are private
D) None of the above
"/>
Latest CMC Aptitude Question SOLUTION: 42) Choose the valid typedef definitions from the following C code snippets
A) typedef struct{...}T;
B) typedef struct S{...}T;
{...}T;
D) typedef struct S{...};
43) What are
42) Choose the valid typedef definitions from the following C code snippets
A) typedef struct{...}T;
B) typedef struct S{...}T;
{...}T;
D) typedef struct S{...};
43) What are the correct ways of accessing member x in the following structure
typedef struct{
int x;
char y;
}T;
T *t = malloc(sizeof(T));
T s;
A) t->x;
B) (*t).x;
C) s.x;
D) All the above.
44) Choose valid statement from the following to declare a variable to hold pointer to an array of functions with return type (char *) and takes an argument int
A) char * (**p) (int x);
B) char * (*p[]) (int x);
C) char * (p[]) (int x);
D) char * (*(*p)) int x;
45) What is the value of the variable z in the following C code snippet at the end of the program
void test(void){
int x=3;
int y=5;
int z;
x += x++;
z = 2 * ++x + y;
}
A) 19
B) 21
C) 15
D) 17
46. What is the result of the variable z in the following C code snippet at the end of the program?
#define modify(A, B) ((A) < (B) ? (++A) : (B--))
int a=4,b=2;
int x = modify(a,b);
a=3;b=6;
int y = modify(a,b);
int z = y - x;
A) 1
B) 2
C) 3
D) None of the above
47) Which of the following doesn't represent a storage class
A) auto
B) public
C) register
D) static
48) Which of the following are not valid C language statements
A) for(;;){}
B) while(true){}
C) while(1){}
D) None of the above
49) Which of the following are not valid function for memory allocation in standard C library
A) malloc()
B) realloc()
C) memalloc()
D) calloc()
50) Which of the following are not valid C language keywords
A) extern
B) function
C) const
D) register
51) What is the value of the variable e in the following C code snippet
int a=3,b=4,c=2,d=3;
int e = (a << 1) * b / c - (d >> 1);
A) 8
B) 10
C) 13
D) None of the above
52) Consider the C language code given below.
int *a;
int b[2];
a = b;
b[0] = -46;
b[1] = -23;
*a = -34;
(*++a)++;
What are the values of b[0], b[1] at the end.
A) -34, -24
B) -46, -22
C) -34, -22
D) -46, -23
53) i=0; sum=0; j=0;
while (i<=50)
{
i = i + (j ? 2 : 3);
j = !j;
sum += i;
}
printf ("%d", sum);
What is the output?
A) 410
B) 630
C) 490
D) 530
54) Assuming all required headers are included, see the below code segment and select the correct option(s) A,B,C and/or D given below and write your comments, if any, on the code segment:
Line 1 : int *iptr ;
Line 2 : printf("Type a number:");
Line 3 : scanf("%d", iptr);
Line 4 : printf("Integer value is %dn", iptr);
A) Missing '&' before 'iptr' in Line 3.
B) Program will cause segmentation fault.
C) Program will not compile as there are errors in this code segment.
D) Program prints the given number in Line 4.
55) int a = 1; b = 2; c = 3;
if( ( a == 1 ) && ( ++b == 2 ) && ( c-- == 1 ) )
{
printf( "%d,%d,%dn", a,b,c );
What is the output ?
A) 1,2,3
B) 1,3,2
C) 2,3,4
D) 1,3,3
56) Assuming all headers required are included. see the program below and answer
and answer
void my_int_alloc( int *i_ptr, int sz ); /* function to allocate memory */
int main()
{
int *int_ptr ;
my_int_alloc(int_ptr,20);
int_ptr[19] = 100;
printf("%d",int_ptr[19]);
free(int_ptr);
return 0;
}
void my_int_alloc( int *i_ptr, int sz )
{
i_ptr = (int *)malloc(sz*sizeof(int)); /* assume malloc never fails */
return;
}
Select the correct option(s) from A, B, C and/or D below:
A) The program has memory leaks and it tries to free unallocated memory.
B) The printf prints the value '100'.
C) There should not be a ‘return’ statement in a function returning void
D) The program will not compile.
57) Assuming all headers are included, see the below program segment and select
and select
the option A, B, C and/or D
char src[11] = "CMC";
char dest[11] = "LIMITED";
strcpy(src+3,dest);
printf("%sn",src);
A) Program has compilation errors in the line having strcpy call.
B) Program results in segmentation fault.
C) Program prints "LIMITED"
D) Program prints "CMCLIMITED"
58) The program
int main(int argc , char *argv[])
{
printf("%sn", ++(*(argv+argc-2)));
return 0;
}
if run with the command
$> prog_name one two three four
will have the below behaviour ( select the right option )
A) program has compilation errors
B) Program prints "three"
C) program prints "hree"
D) program prints "three four"
59) Which of the following statements are valid regarding "static" variables in C?
A) Have global scope and lifetime till the end of the program.
B) Have block scope and lifetime till the end of the block.
C) Have block scope and lifetime till the end of the program.
D) Have global scope and lifetime till the end of the block
60) What is the output of the code segment below?
char c;
int i = 0 ;
for( c = 'A' + i ; c < 'Z' ; c += 2,i++ )
{
printf("%c", c);
}
A) ADHMS (skips 2,3,4,5 characters in between A and Z)
B) ACEGIKMOQSUWY (skips one char in between A and Z)
C) ABCDEFGHI...Y (prints all characters from A to Y)
D) Program does not compile.
61) Select the correct statements in relation to the "realloc" function
A) The realloc tries to allocate new memory which starts at the old memory and if it cannot find sequential memory extending the old memory, realloc will fail...
B) After the call to realloc, we need to copy the data from the old pointer
C) Based on where the new memory is allocated, the realloc function takes care
Of copying the data into the new location, but the caller needs to free the
D) Both data copy and freeing of old memory whenever required, is taken care
62) In the declaration char c_arr[100] = "CMCLIMITED" ; , c_arr is :
A) a constant pointer to character.
B) non-const pointer to a character constant.
C) non-const pointer to character.
D) a constant pointer to constant character.
63) Looking at the code lines below, select the correct statement(s) below:
Line 1 char *c_ptr;
Line 2 char a_arr[100];
Line 3 c_ptr = (char *) malloc (10*sizeof (int));
Line 4 c_ptr = c_arr;
Line 5 free (c_ptr);
A) Line 3 has compilation error: it uses sizeof (int) instead of sizeof (char)
B) Line 4 has an error as we cannot assign an array pointer to a normal pointer.
C) Line 5 has a compilation error.
D) Line 5 has undefined behavior.
64) Which of the following functions deal with binary output into a file?
A) fprintf()
B) fputs();
C) fwrite();
D) All of the above.
65) Which of the following are valid file operation functions in C?
A) fseek()
B) ftell()
C) rewind()
D) All of the above.
66) Assuming all headers included, indicate the behavior of the below program:
Int arr[10] = {1,2,3,4,5,6,7,8,9,10};
Int I = 0;
while( I < 10 )
{
printf(“%dn”, *(arr++));
}
A) prints numbers from 1 to 10
B) prints numbers from 1 to 9
C) prints ‘1’ ten times.
D) program has compilation errors.
67) Given a structure typedef struct { char x; int y, int z} mystruct;
sizeof(mystruct) will return
A) 5 -- Always
B) 6 -- Some times
C) 8 -- Based on Memory size
D) None of the above
68) char *p = (char*) malloc(2000000*2/10+4);
int length = strlen(p);
Output of the above program:
A) 400004
B) 200002
C) NULL
D) None of the above
69) A program is written in “C” language , and an executable is made by compiling it on unix/linux environment. Can we run the executable on windows operating system.
A) Yes, Always
B) Only on vista operating system
C) Never
D) If we change extension to .exe, it will run
70) Main difference of a struct in C and C++
A) In C members are private, c++ members are virtual
B) In C members are public, c++ members are private
C) In C members are virtual, c++ members are private
D) None of the above
Pure mathematics is the world's best game. It is more absorbing than chess, more of a gamble than poker, and lasts longer than Monopoly. It's free. It can be played anywhere - Archimedes did it in a bathtub.