1. In the following program, what would be the final output? Explain in
detail.
void copyarr( char ∗p1 , char p2 [ ] ) {
memcpy ( p2 , p1 , size of ( p1 ) ) ;
memcpy ( p2 , ‘ ‘ABCD’ ’ , 4 ) ;
}
int main ( ) {
char arr1 [ 100 ] ;
char arr2 [ 100 ] ;
printf( ‘ ‘ Enter a string : ’ ’ ) ;
scanf ( ‘ ‘%[ ˆ\n ] s ’ ’ , arr1 ) ;
copyarr ( arr1 , arr2 ) ;
printf ( ‘ ‘ \ n %s ’ ’ , arr2 ) ;
return 0 ;
}
void copyarr( char ∗p1 , char p2 [ ] ) {
memcpy ( p2 , p1 , size of ( p1 ) ) ;
memcpy ( p2 , ‘ ‘ABCD’ ’ , 4 ) ;
}
int main ( ) {
char arr1 [ 100 ] ;
char arr2 [ 100 ] ;
printf( ‘ ‘ Enter a string : ’ ’ ) ;
scanf ( ‘ ‘%[ ˆ\n ] s ’ ’ , arr1 ) ;
copyarr ( arr1 , arr2 ) ;
printf ( ‘ ‘ \ n %s ’ ’ , arr2 ) ;
return 0 ;
}
The program does not compile.
It contains errors
Comments
Leave a comment