C. reading program questions during the interview

Source: Internet
Author: User

C. reading program question ZZ during the interview
Shury published on 17:50:00

What will print out?
Main ()
{
Char * P1 = "name ";
Char * P2;
P2 = (char *) malloc (20 );
Memset (P2, 0, 20 );
While (* P2 ++ = * P1 ++ );
Printf ("% Sn", P2 );

}

Answer: empty string.

What will be printed as the result of the Operation below:

Main ()
{
Int x = 20, y = 35;
X = y ++ x ++;
Y = ++ y ++ X;
Printf ("% d % DN", x, y );
}

Answer: 5794

What will be printed as the result of the Operation below:

Main ()
{
Int x = 5;
Printf ("% d, % d, % DN", x, x <2, x> 2 );
}

Answer: 5, 20, 1

What will be printed as the result of the Operation below:

# Define swap (A, B) A = a + B; B = A-B; A = A-B;
Void main ()
{
Int x = 5, y = 10;
Swap (x, y );
Printf ("% d % DN", x, y );
Swap2 (x, y );
Printf ("% d % DN", x, y );
}

Int swap2 (int A, int B)
{
Int temp;
Temp =;
B =;
A = temp;
Return 0;

}

Answer: 10, 5
10, 5

What will be printed as the result of the Operation below:

Main ()
{
Char * PTR = "Cisco Systems ";
* PTR ++; printf ("% Sn", PTR );
PTR ++;
Printf ("% Sn", PTR );
}

Answer: Cisco Systems
ISCO Systems

What will be printed as the result of the Operation below:

Main ()
{
Char S1 [] = "Cisco ";
Char S2 [] = "systems ";
Printf ("% s", S1 );
}
Answer: Cisco

What will be printed as the result of the Operation below:

Main ()
{
Char * P1;
Char * P2;
P1 = (char *) malloc (25 );
P2 = (char *) malloc (25 );

Strcpy (P1, "Cisco ");
Strcpy (P2, "systems ");
Strcat (P1, P2 );

Printf ("% s", P1 );

}

Answer: ciscosystems

The following variable is available in file1.c, who can access it? :

Static int average;

Answer: all the functions in the file1.c can access the variable.

What will be the result of the following code?

# Define true 0 // some code
While (true)
{

// Some code

}

Answer: This will not go into the loop as true is defined as 0.

What will be printed as the result of the Operation below:

Int X;
Int modifyvalue ()
{
Return (x + = 10 );
}
Int changevalue (int x)
{
Return (x + = 1 );
}

Void main ()
{
Int x = 10;
X ++;
Changevalue (X );
X ++;
Modifyvalue ();
Printf ("first output: % DN", X );

X ++;
Changevalue (X );
Printf ("second output: % DN", X );
Modifyvalue ();
Printf ("third output: % DN", X );

}

Answer: 12, 13, 13

What will be printed as the result of the Operation below:

Main ()
{
Int x = 10, y = 15;
X = x ++;
Y = ++ y;
Printf ("% d % DN", x, y );
}

Answer: 11, 16

What will be printed as the result of the Operation below:

Main ()
{
Int A = 0;
If (A = 0)
Printf ("Cisco systemsn ");
Printf ("Cisco systemsn ");
}

Answer: two lines with "Cisco Systems" will be printed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.