CSCI-0046 Systems Programming in Linux – MIDTERM
Questions With Complete Solutions
! operator Correct Answer returns TRUE when condition is
FALSE and returns FALSE when condition is TRUE. So the
opposite of the condition.
// Jack wrote a function to increment the value of x. But he is
using a pointer as the parameter
// Which statement inside the function will do the job of
incrementing .
int func ( int *x )
{
// which is statement is valid ?
// statement 1 :
*x++ ;
// statement 2
* ( x++ ) ;
// statement 3
( *x ) ++ ;
}
main ( )
{
int x = 10 ;
func ( &x ) ;
printf ( " x = %d \n " x );
} Correct Answer statement 3
,&& (AND) Operator Correct Answer returns TRUE when
ALL the conditions under consideration are true and returns
FALSE when any ONE or MORE than one condition is false.
#include <stdio.h>
int main ( )
{
int x = 10;
switch x
{
case 10 :
printf ( "Yes" );
break ;
}
}
// The above code compiles fine. True or False Correct Answer
False- Yes, there should be ( ) around x in the switch statement
all data cells in this array will have a value of 4
int data [ 6 ] = { 4 } ; Correct Answer False
Cells in an array are contiguous Correct Answer True
char data [ 2 ] [ 3 ] = { { 2, 3 , 0} , { 1 , 4, 5 } } ;
int i ;
for ( i = 0 ; i < 3 ; i++ )printf ( "%d ", data [ 1 ] [ i ] );
The above code would print Correct Answer 1 4 5
, How to declare an array-1D? Correct Answer dataType
arrayName[arraySize];
How to define a pointer variable? Correct Answer int *ptr ;
ptr is now a pointer variable
if ( -10 )
printf ( "Yes \n" );
else
printf ( "No\n");
The above statement would print Yes.
True or False Correct Answer True
if ( 0 )
printf ( "Yes \n" );
else
printf ( "No\n");
The above statement would print Yes.
True or False Correct Answer False
int * ptr = 20 ;
int y = *ptr ;
The above statement WILL give you run-time error
TRUE OR FALSE Correct Answer True - Yes,
ptr = 20 is illegal because you are assigning 20 (a address
somewhere in the kernel ) to ptr. When you access the value
Questions With Complete Solutions
! operator Correct Answer returns TRUE when condition is
FALSE and returns FALSE when condition is TRUE. So the
opposite of the condition.
// Jack wrote a function to increment the value of x. But he is
using a pointer as the parameter
// Which statement inside the function will do the job of
incrementing .
int func ( int *x )
{
// which is statement is valid ?
// statement 1 :
*x++ ;
// statement 2
* ( x++ ) ;
// statement 3
( *x ) ++ ;
}
main ( )
{
int x = 10 ;
func ( &x ) ;
printf ( " x = %d \n " x );
} Correct Answer statement 3
,&& (AND) Operator Correct Answer returns TRUE when
ALL the conditions under consideration are true and returns
FALSE when any ONE or MORE than one condition is false.
#include <stdio.h>
int main ( )
{
int x = 10;
switch x
{
case 10 :
printf ( "Yes" );
break ;
}
}
// The above code compiles fine. True or False Correct Answer
False- Yes, there should be ( ) around x in the switch statement
all data cells in this array will have a value of 4
int data [ 6 ] = { 4 } ; Correct Answer False
Cells in an array are contiguous Correct Answer True
char data [ 2 ] [ 3 ] = { { 2, 3 , 0} , { 1 , 4, 5 } } ;
int i ;
for ( i = 0 ; i < 3 ; i++ )printf ( "%d ", data [ 1 ] [ i ] );
The above code would print Correct Answer 1 4 5
, How to declare an array-1D? Correct Answer dataType
arrayName[arraySize];
How to define a pointer variable? Correct Answer int *ptr ;
ptr is now a pointer variable
if ( -10 )
printf ( "Yes \n" );
else
printf ( "No\n");
The above statement would print Yes.
True or False Correct Answer True
if ( 0 )
printf ( "Yes \n" );
else
printf ( "No\n");
The above statement would print Yes.
True or False Correct Answer False
int * ptr = 20 ;
int y = *ptr ;
The above statement WILL give you run-time error
TRUE OR FALSE Correct Answer True - Yes,
ptr = 20 is illegal because you are assigning 20 (a address
somewhere in the kernel ) to ptr. When you access the value