what is the output of all these program ??
第一题
#include<stdio.h>
char* bar (char *ptr)
{
ptr += 3;
return (ptr);
}
int main()
{
char *xvar, *yvar;
xvar = "India";
yvar = bar (xvar);
printf ("yvar = %s \n", yvar);
return 0;
}
第二题
#include<stdio.h>
int func()
{
int static num=10;
return num--;
}
int main()
{
extern func();
for(func ();func();func())
printf("%d ",func());
return 0;
}
第三题
#include<stdio.h>
void main()
{
const int *xval;
xval =10;
printf("%d", xval) ;
}
第四题
#include<stdio.h>
int main()
{
printf(5+"Life is beautiful\n");
return 0;
}
第五题
#include<stdio.h>
int func(void* a, void* b)
{
if(*a > *b)
printf("%d", *a);
else
printf("%d", *b);
}
int main()
{
int a = 10, b = 8;
func(&a, &b);
return 0;
}
第六题
#include<stdio.h>
void main()
{
int *i = 100,j;
j = &i;
i++;
if (i !=100 && j==&i)
printf ("Same");
else if (i !=100 && j!=&i)
printf ("Not Same");
else printf ("");
}
第七题
#include <iostream.h>
void function(char Easter)
{
for(char VS enclave= 'A'; VS enclave< Easter; VS enclave++)
cout << " ";
if(Easter <= 'E')
{
cout << "Easter " << Easter << endl;
function(Easter + 1);
}
else
cout << "Yummy" << endl;
}
int main()
{
function('A');
}
更正,无编译错误后的输出
#include <iostream.h>
void function(char Easter)
{
for(char VSenclave= 'A'; VSenclave< Easter; VSenclave++)
cout << " ";
if(Easter <= 'E')
{
cout << "Easter " << Easter << endl;
function(Easter + 1);
}
else
cout << "Yummy" << endl;
}
int main()
{
function('A');
return 0;
}
第八题
#include<iostream>
using namespace std;
int main ()
{
char * str = "Hello";
cout<< strlen(str)+1 + "Hello World";
cout<< "Hello World" - 6<<endl;
return 0;
}
第九题
#include<iostream>
using namespace std;
int main ()
{
int * arr = new int[5][5];
return 0;
}
第十题
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystr;
string mystr2="Hello ";
string mystr3="World";
mystr.append(mystr2);
mystr.append(mystr3,6,3);
mystr.append(mystr3.begin()+2,mystr3.end());
cout << mystr << endl;
return 0;
}
第十一题
#include <iostream>
#include <string>
using namespace std;
int addition (int a, int b)
{ return (a+b); }
int subtraction (int a, int b)
{ return (a-b); }
int operation (int x, int y, int (*functocall)(int,int))
{
int g;
g = (*functocall)(x,y);
return (g);
}
int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;
m = operation (7, 5, addition);
n = operation (20, m, minus);
cout <<n;
return 0;
}
Output
1. yvar = ia ;
2. 8 5 2
3. compile error
4. is beautiful
5. compile error
6. compile error
7. compile error
8. World
9. compile error
10. runtime error
mystr.append(mystr3,4,3) = d ;
11. 8