求破,为啥最后third那里c的值为5

c语言编写行列式求值有问题,求破解_百度知道
c语言编写行列式求值有问题,求破解
我想编写行列式求值,但是程序显示(fun2 和main函数local function definitions are illegal)和(cpp(50) : fatal error C1004: unexpected end of file found ),求破解#includeint b[10][10]={0};int fun1(int a[2][2]){
x=a[0][0]*a[1][1]-a[0][1]*a[1][0]; return(x);}void tran(int a[][10],int m,int n){
int i,j,k,l; for(i=0,k=1;k&n;i++,k++) { for(j=0,l=0;l&m;j++,l++) b[i][j]=a[k][l]; for(l=m+1;l&n;j++,l++) b[i][j]=a[k][l]; }int fun2(int a[][10],int n){ int x=0,i,k,c[10]; if(n=2)
x=fun1(a); else { for(i=0;i&n;i++)
c[i]=a[0][i]*fun2(tran(a,i,n-1),n-1); for(i=1;i&n;i++)
for(k=1;k&=i;k++) c[i]=(-1)*c[i];for(i=0;i&n;i++) x=x+c[i]; }
return(x);}void main (){ int a[10][10],n,i,j,x; printf(&输入行列式阶数&); scanf(&%d&,&n); printf(&输入行列式&); for(i=0;i&n;i++)
for(j=0;j&n;j++)
scanf(&%d&,&a[i][j]);
x=fun2(a,n-1);
printf(&行列式值为%d&,x);}
提问者采纳
你的代码写得太乱,整理后如下,所以有问题。#includeint&b[10][10]={0};int&fun1(int&a[2][2]){&&&&int&x;&&&&x=a[0][0]*a[1][1]-a[0][1]*a[1][0];&&&&&&&&return(x);}void&tran(int&a[][10],int&m,int&n){&&&&&&int&i,j,k,l;&&&&&for(i=0,k=1;k&n;i++,k++)&&&&&&&&{&&&&&&&&&for(j=0,l=0;l&m;j++,l++)&&&&&&&&&&&&b[i][j]=a[k][l];&&&&&&&&&for(l=m+1;l&n;j++,l++)&&&&&&&&&&&&b[i][j]=a[k][l];&&&&&}&&&&int&fun2(int&a[][10],int&n)&&&&{&&&&&&&&&&&&int&x=0,i,k,c[10];&&&&&&&&if(n=2)&&&&&&&&&&&&x=fun1(a);&&&&&&&&else&&&&&&&&{&&&&&&&&&&&&for(i=0;i&n;i++)&&&&&&&&&&&&&&&&&&&&c[i]=a[0][i]*fun2(tran(a,i,n-1),n-1);&&&&&&&&&&&&for(i=1;i&n;i++)&&&&&&&&&&&&&&&&&&&&for(k=1;k&=i;k++)&&&&&&&&&&&&&&&&&&&&c[i]=(-1)*c[i];&&&&&&&&&&&&for(i=0;i&n;i++)&&&&&&&&&&&&&&&&x=x+c[i];&&&&&&&&}&&&&&&&&return(x);&&&&}&&&&void&main&()&&&&{&&&&&&&&int&a[10][10],n,i,j,x;&&&&&&&&printf(&输入行列式阶数&);&&&&&&&&scanf(&%d&,&n);&&&&printf(&输入行列式&);&&&&&&&&&&&&for(i=0;i&n;i++)&&&&&&&&&&&&&&&&for(j=0;j&n;j++)&&&&&&&&&&&&&&&&&&&&&&&&&&scanf(&%d&,&a[i][j]);&&&&&&&&&&&&x=fun2(a,n-1);&&&&&&&&&&printf(&行列式值为%d&,x);&&&&}
其他类似问题
行列式的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁4041人阅读
1.求下面函数的返回值(微软)
int func(x) { &&& int countx = 0; &&& while(x) &&& { &&&&&&&&& countx ++; &&&&&&&&& x = x&(x-1); &&&& } &&& }&
假定x = 9999。 答案:8
思路:将x转化为2进制,看含有的1的个数。
2. 什么是&引用&?申明和使用&引用&要注意哪些问题?
答:引用就是某个目标变量的&别名&(alias),对应用的操作与对变量直接操作效果完全相同。申明一个引用的时候,切记要对其进行初始化。引用声明完毕后,相当于目标变量名有两个名称,即该目标原名称和引用名,不能再把该引用名作为其他变量名的别名。声明一个引用,不是新定义了一个变量,它只表示该引用名是目标变量名的一个别名,它本身不是一种数据类型,因此引用本身不占存储单元,系统也不给引用分配存储单元。不能建立数组的引用。
3. 将&引用&作为函数参数有哪些特点?
(1)传递引用给函数与传递指针的效果是一样的。这时,被调函数的形参就成为原来主调函数中的实参变量或对象的一个别名来使用,所以在被调函数中对形参变量的操作就是对其相应的目标对象(在主调函数中)的操作。
(2)使用引用传递函数的参数,在内存中并没有产生实参的副本,它是直接对实参操作;而使用一般变量传递函数的参数,当发生函数调用时,需要给形参分配存储单元,形参变量是实参变量的副本;如果传递的是对象,还将调用拷贝构造函数。因此,当参数传递的数据较大时,用引用比用一般变量传递参数的效率和所占空间都好。
(3)使用指针作为函数的参数虽然也能达到与使用引用的效果,但是,在被调函数中同样要给形参分配存储单元,且需要重复使用&*指针变量名&的形式进行运算,这很容易产生错误且程序的阅读性较差;另一方面,在主调函数的调用点处,必须用变量的地址作为实参。而引用更容易使用,更清晰。
4. 在什么时候需要使用&常引用&? 
如果既要利用引用提高程序的效率,又要保护传递给函数的数据不在函数中被改变,就应使用常引用。常引用声明方式:const 类型标识符 &引用名=目标变量名;
const int &ra=a;ra=1; //错误a=1; //正确
string foo( );void bar(string & s);
那么下面的表达式将是非法的:
bar(foo( ));bar(&hello world&);
原因在于foo( )和&hello world&串都会产生一个临时对象,而在C++中,这些临时对象都是const类型的。因此上面的表达式就是试图将一个const类型的对象转换为非const类型,这是非法的。
引用型参数应该在能被定义为const的情况下,尽量定义为const 。
5. 将&引用&作为函数返回值类型的格式、好处和需要遵守的规则?
格式:类型标识符 &函数名(形参列表及类型说明){ //函数体 }
好处:在内存中不产生被返回值的副本;(注意:正是因为这点原因,所以返回一个局部变量的引用是不可取的。因为随着该局部变量生存期的结束,相应的引用也会失效,产生runtime error!
注意事项:
(1)不能返回局部变量的引用。这条可以参照Effective C++[1]的Item 31。主要原因是局部变量会在函数返回后被销毁,因此被返回的引用就成为了&无所指&的引用,程序会进入未知状态。
(2)不能返回函数内部new分配的内存的引用。这条可以参照Effective C++[1]的Item 31。虽然不存在局部变量的被动销毁问题,可对于这种情况(返回函数内部new分配内存的引用),又面临其它尴尬局面。例如,被函数返回的引用只是作为一个临时变量出现,而没有被赋予一个实际的变量,那么这个引用所指向的空间(由new分配)就无法释放,造成memory leak。
(3)可以返回类成员的引用,但最好是const。这条原则可以参照Effective C++[1]的Item 30。主要原因是当对象的属性是与某种业务规则(business rule)相关联的时候,其赋值常常与某些其它属性或者对象的状态有关,因此有必要将赋值操作封装在一个业务规则当中。如果其它对象可以获得该属性的非常量引用(或指针),那么对该属性的单纯赋值就会破坏业务规则的完整性。
(4)流操作符重载返回值申明为&引用&的作用:
流操作符&&和&&,这两个操作符常常希望被连续使用,例如:cout && &hello& && 因此这两个操作符的返回值应该是一个仍然支持这两个操作符的流引用。可选的其它方案包括:返回一个流对象和返回一个流对象指针。但是对于返回一个流对象,程序必须重新(拷贝)构造一个新的流对象,也就是说,连续的两个&&操作符实际上是针对不同对象的!这无法让人接受。对于返回一个流指针则不能连续使用&&操作符。因此,返回一个流对象引用是惟一选择。这个唯一选择很关键,它说明了引用的重要性以及无可替代性,也许这就是C++语言中引入引用这个概念的原因吧。 赋值操作符=。这个操作符象流操作符一样,是可以连续使用的,例如:x = j = 10;或者(x=10)=100;赋值操作符的返回值必须是一个左值,以便可以被继续赋值。因此引用成了这个操作符的惟一返回值选择。
#i nclude &iostream.h&int &put(int n);int vals[10];int error=-1;void main(){put(0)=10; //以put(0)函数值作为左值,等价于vals[0]=10; put(9)=20; //以put(9)函数值作为左值,等价于vals[9]=20; cout&&vals[0]; cout&&vals[9];} int &put(int n){if (n&=0 && n&=9 ) return vals[n]; else { cout&&&subscript error&; }}
(5)在另外的一些操作符中,却千万不能返回引用:+-*/ 四则运算符。它们不能返回引用,Effective C++[1]的Item23详细的讨论了这个问题。主要原因是这四个操作符没有side effect,因此,它们必须构造一个对象作为返回值,可选的方案包括:返回一个对象、返回一个局部变量的引用,返回一个new分配的对象的引用、返回一个静态对象引用。根据前面提到的引用作为返回值的三个规则,第2、3两个方案都被否决了。静态对象的引用又因为((a+b) == (c+d))会永远为true而导致错误。所以可选的只剩下返回一个对象了。
6. &引用&与多态的关系?
引用是除指针外另一个可以产生多态效果的手段。这意味着,一个基类的引用可以指向它的派生类实例。
Class A; Class B : Class A{...};& B A& ref =
7. &引用&与指针的区别是什么?
指针通过某个指针变量指向一个对象后,对它所指向的变量间接操作。程序中使用指针,程序的可读性差;而引用本身就是目标变量的别名,对引用的操作就是对目标变量的操作。此外,就是上面提到的对函数传ref和pointer的区别。
8. 什么时候需要&引用&?
流操作符&&和&&、赋值操作符=的返回值、拷贝构造函数的参数、赋值操作符=的参数、其它情况都推荐使用引用。
以上 2-8 参考:
9. 结构与联合有和区别?1. 结构和联合都是由多个不同的数据类型成员组成, 但在任何同一时刻, 联合中只存放了一个被选中的成员(所有成员共用一块地址空间), 而结构的所有成员都存在(不同成员的存放地址不同)。&&2. 对于联合的不同成员赋值, 将会对其它成员重写,& 原来成员的值就不存在了, 而对于结构的不同成员赋值是互不影响的。
10. 下面关于&联合&的题目的输出?
#i nclude &stdio.h&union{char x[2];}a;
void&main(){a.x[0] = 10; a.x[1] = 1;printf(&%d&,a.i);}答案:266 (低位低地址,高位高地址,内存占用情况是Ox010A)
&&&& main() &&&& { &&&&&&&&& union{&&&&&&&&&&&&&&&&&& /*定义一个联合*/ &&&&&&&&&&&&&& &&&&&&&&&&&&&& struct{&&&&&&&&&&&& /*在联合中定义一个结构*/ &&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&& } &&&&&&&&& } &&&&&&&&& number.i=0x4241;&&&&&&&& /*联合成员赋值*/ &&&&&&&&& printf(&%c%c/n&, number.half.first, mumber.half.second); &&&&&&&&& number.half.first='a';&& /*联合中结构成员赋值*/ &&&&&&&&& number.half.second='b'; &&&&&&&&& printf(&%x/n&, number.i); &&&&&&&&& getch(); &&&& } 答案: AB&& (0x41对应'A',是低位;Ox42对应'B',是高位)
&&&&&&&6261 (number.i和number.half共用一块地址空间)
11. 已知strcpy的函数原型:char *strcpy(char *strDest, const char *strSrc)其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy。
答案:char *strcpy(char *strDest, const char *strSrc){if ( strDest == NULL || strSrc == NULL)return NULL ;if ( strDest == strSrc)return strDchar *tempptr = strDwhile( (*strDest++ = *strSrc++) != &/0&);}
12. 已知String类定义如下:
class String{public:String(const char *str = NULL); // 通用构造函数String(const String &another); // 拷贝构造函数~ String(); // 析构函数String & operater =(const String &rhs); // 赋值函数private:char *m_ // 用于保存字符串};
尝试写出类的成员函数实现。
String::String(const char *str){&&&if ( str == NULL ) //strlen在参数为NULL时会抛异常才会有这步判断&&&& {&&&&&&&m_data = new char[1] ;&&&&&&&m_data[0] = '/0' ;&&&&&}&& else&&&&{&&&&&& m_data = new char[strlen(str) + 1];&&&&&& strcpy(m_data,str);&&&&}
String::String(const String &another){&&& m_data = new char[strlen(another.m_data) + 1];&&& strcpy(m_data,other.m_data);}
String& String::operator =(const String &rhs){&&&&if ( this == &rhs)&&&&&&&&return *&&& delete []m_ //删除原来的数据,新开一块内存&&& m_data = new char[strlen(rhs.m_data) + 1];&&& strcpy(m_data,rhs.m_data);&&&&return *}
String::~String(){&&& delete []m_}
13. .h头文件中的ifndef/define/endif 的作用?
答:防止该头文件被重复引用。
14. #i nclude&file.h& 与 #i nclude &file.h&的区别?
答:前者是从Standard Library的路径寻找和引用file.h,而后者是从当前工作路径搜寻并引用file.h。
15.在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern &C&?
首先,作为extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,该关键字告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用。
通常,在模块的头文件中对本模块提供给其它模块引用的函数和全局变量以关键字extern声明。例如,如果模块B欲引用该模块A中定义的全局变量和函数时只需包含模块A的头文件即可。这样,模块B中调用模块A中的函数时,在编译阶段,模块B虽然找不到该函数,但是并不会报错;它会在连接阶段中从模块A编译生成的目标代码中找到此函数
extern &C&是连接申明(linkage declaration),被extern &C&修饰的变量和函数是按照C语言方式编译和连接的,来看看C++中对类似C的函数是怎样编译的:作为一种面向对象的语言,C++支持函数重载,而过程式语言C则不支持。函数被C++编译后在符号库中的名字与C语言的不同。例如,假设某个函数的原型为:
void foo( int x, int y );  
该函数被C编译器编译后在符号库中的名字为_foo,而C++编译器则会产生像_foo_int_int之类的名字(不同的编译器可能生成的名字不同,但是都采用了相同的机制,生成的新名字称为&mangled name&)。_foo_int_int这样的名字包含了函数名、函数参数数量及类型信息,C++就是靠这种机制来实现函数重载的。例如,在C++中,函数void foo( int x, int y )与void foo( int x, float y )编译生成的符号是不相同的,后者为_foo_int_float。
同样地,C++中的变量除支持局部变量外,还支持类成员变量和全局变量。用户所编写程序的类成员变量可能与全局变量同名,我们以&.&来区分。而本质上,编译器在进行编译时,与函数的处理相似,也为类中的变量取了一个独一无二的名字,这个名字与用户程序中同名的全局变量名字不同。未加extern &C&声明时的连接方式
假设在C++中,模块A的头文件如下:
// 模块A头文件 moduleA.h#ifndef MODULE_A_H#define MODULE_A_Hint foo( int x, int y );#endif  
在模块B中引用该函数:
// 模块B实现文件 moduleB.cpp#i nclude &moduleA.h&foo(2,3);  
实际上,在连接阶段,连接器会从模块A生成的目标文件moduleA.obj中寻找_foo_int_int这样的符号!加extern &C&声明后的编译和连接方式加extern &C&声明后,模块A的头文件变为:
// 模块A头文件 moduleA.h#ifndef MODULE_A_H#define MODULE_A_Hextern &C& int foo( int x, int y );#endif  
在模块B的实现文件中仍然调用foo( 2,3 ),其结果是:(1)模块A编译生成foo的目标代码时,没有对其名字进行特殊处理,采用了C语言的方式;
(2)连接器在为模块B的目标代码寻找foo(2,3)调用时,寻找的是未经修改的符号名_foo。如果在模块A中函数声明了foo为extern &C&类型,而模块B中包含的是extern int foo( int x, int y ) ,则模块B找不到模块A中的函数;反之亦然。所以,可以用一句话概括extern &C&这个声明的真实目的(任何语言中的任何语法特性的诞生都不是随意而为的,来源于真实世界的需求驱动。我们在思考问题时,不能只停留在这个语言是怎么做的,还要问一问它为什么要这么做,动机是什么,这样我们可以更深入地理解许多问题):实现C++与C及其它语言的混合编程。  
明白了C++中extern &C&的设立动机,我们下面来具体分析extern &C&通常的使用技巧:
extern &C&的惯用法(1)在C++中引用C语言中的函数和变量,在包含C语言头文件(假设为cExample.h)时,需进行下列处理:
extern &C&{#i nclude &cExample.h&}
而在C语言的头文件中,对其外部函数只能指定为extern类型,C语言中不支持extern &C&声明,在.c文件中包含了extern &C&时会出现编译语法错误。C++引用C函数例子工程中包含的三个文件的源代码如下:
/* c语言头文件:cExample.h */#ifndef C_EXAMPLE_H#define C_EXAMPLE_Hextern int add(int x,int y);#endif
/* c语言实现文件:cExample.c */#i nclude &cExample.h&int add( int x, int y ){return x +}
// c++实现文件,调用add:cppFile.cppextern &C& {#i nclude &cExample.h&}int main(int argc, char* argv[]){add(2,3); return 0;}
如果C++调用一个C语言编写的.DLL时,当包括.DLL的头文件或声明接口函数时,应加extern &C& { }。
(2)在C中引用C++语言中的函数和变量时,C++的头文件需添加extern &C&,但是在C语言中不能直接引用声明了extern &C&的该头文件,应该仅将C文件中将C++中定义的extern &C&函数声明为extern类型。
C引用C++函数例子工程中包含的三个文件的源代码如下:
//C++头文件 cppExample.h#ifndef CPP_EXAMPLE_H#define CPP_EXAMPLE_Hextern &C& int add( int x, int y );#endif
//C++实现文件 cppExample.cpp#i nclude &cppExample.h&int add( int x, int y ){return x +}
/* C实现文件 cFile.c/* 这样会编译出错:#i nclude &cExample.h& */extern int add( int x, int y );int main( int argc, char* argv[] ){add( 2, 3 ); return 0;}
15题目的解答请参考注解:
16. 关联、聚合(Aggregation)以及组合(Composition)的区别?
涉及到UML中的一些概念:关联是表示两个类的一般性联系,比如&学生&和&老师&就是一种关联关系;聚合表示has-a的关系,是一种相对松散的关系,聚合类不需要对被聚合类负责,如下图所示,用空的菱形表示聚合关系:
&&&&&&&&&&&&&&&&&&&&&&&&&&&
从实现的角度讲,聚合可以表示为:
class A {...}& class B { A* .....}
而组合表示contains-a的关系,关联性强于聚合:组合类与被组合类有相同的生命周期,组合类要对被组合类负责,采用实心的菱形表示组合关系:
&&&&&&&&&&&&&&&&&&&&&&&&&&&
实现的形式是:
class A{...} class B{ A ...}
参考文章:
17.面向对象的三个基本特征,并简单叙述之?
1. 封装:将客观事物抽象成类,每个类对自身的数据和方法实行protection(private, protected,public)
2. 继承:广义的继承有三种实现形式:实现继承(指使用基类的属性和方法而无需额外编码的能力)、可视继承(子窗体使用父窗体的外观和实现代码)、接口继承(仅使用属性和方法,实现滞后到子类实现)。前两种(类继承)和后一种(对象组合=&接口继承以及纯虚函数)构成了功能复用的两种方式。
3. 多态:是将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作。简单的说,就是一句话:允许将子类类型的指针赋值给父类类型的指针。
18. 重载(overload)和重写(overried,有的书也叫做&覆盖&)的区别?
常考的题目。从定义上来说:
重载:是指允许存在多个同名函数,而这些函数的参数表不同(或许参数个数不同,或许参数类型不同,或许两者都不同)。
重写:是指子类重新定义复类虚函数的方法。
从实现原理上来说:
重载:编译器根据函数不同的参数表,对同名函数的名称做修饰,然后这些同名函数就成了不同的函数(至少对于编译器来说是这样的)。如,有两个同名函数:function func(p:integer):function func(p:string):。int_funcstr_func
ulong int 4
ulong double
1. Consider the following program:
#include&setjmp.h&
static jmp_buf&
& volatile&
& if(setjmp(buf)!=0)&
&&& printf(&%d &, b);&
&&& exit(0);
& longjmp(buf , 1);
The output for this program is: &(a) 3(b) 5(c) 0(d) None of the above
2. Consider the following program:
&& struct node
&& struct node& s= { 3, 5,6 };
&& struct node *pt = &s;
&& printf(&%d& ,& *(int*)pt);
The output for this program is: (a) 3(b) 5(c) 6(d) 7
3. Consider the following code segment:
int& foo ( int x , int& n)
& if (n&0)
&&& if (n%2 == 1)& val = val *x;
&&& val = val * foo(x*x , n/2);
What function of x and n is compute by this code segment?& &
(a) x^n(b) x*n(c) n^x(d) None of the above
4. Consider the following program:
& int& a[5] = {1,2,3,4,5};
& int *ptr =& (int*)(&a+1);
& printf(&%d %d& , *(a+1), *(ptr-1) );
The output for this program is: (a) 2 2(b) 2 1(c) 2 5(d) None of the above
5. Consider the following program:
void foo(int [][3] );&&&&
& int a [3][3]= { { 1,2,3} , { 4,5,6},{7,8,9}};
& printf(&%d& , a[2][1]);
void foo( int b[][3])
& b[1][1] =9;
The output for this program is: (a) 8(b) 9(c) 7(d) None of the above
6. Consider the following program:
& int a, b,c,
& d=(a,b);
& printf(&c=%d& ,c);
& printf(&d=%d& ,d);
The output for this program is: (a) c=3 d=3(b) c=5 d=3(c) c=3 d=5(d) c=5 d=5
7. Consider the following program:
& int a[][3] = { 1,2,3 ,4,5,6};
& int (*ptr)[3] =a;
& printf(&%d %d && ,(*ptr)[1], (*ptr)[2] );
& printf(&%d %d&& ,(*ptr)[1], (*ptr)[2] );
The output for this program is: (a) 2 3 5 6(b) 2 3 4 5(c) 4 5 0 0(d) None of the above
8. Consider following function
int *f1(void)
& int x =10;
& return(&x);
int *f2(void)
& *ptr =10;
int *f3(void)
& ptr=(int*) malloc(sizeof(int));
Which of the above three functions are likely to cause problem with pointers (a) Only f3(b) Only f1 and f3(c) Only f1 and f2(d) f1 , f2 ,f3
9. Consider the following program:
& int i=3;
& j = sizeof(++i+ ++i);
& printf(&i=%d j=%d&, i ,j);
The output for this program is:(a) i=4 j=2(b) i=3 j=2(c) i=3 j=4(d) i=3 j=6
10. Consider the following program:
void f1(int *, int);
void f2(int *, int);
void(*p[2]) ( int *, int);
& p[0] = f1;
& p[1] = f2;
& p[0](&a , b);
& printf(&%d/t %d/t& , a ,b);
& p[1](&a , b);
& printf(&%d/t %d/t& , a ,b);
void f1( int* p , int q)
& tmp =*p;
void f2( int* p , int q)
& tmp =*p;
The output for this program is: (a) 5 5 5 5(b) 3 5 3 5(c) 5 3 5 3(d) 3 3 3 3
11. Consider the following program:
void e(int );&&
void e(int n)
&&& e(--n);
&&& printf(&%d& , n);
& &&e(--n);
The output for this program is: (a) 0 1 2 0(b) 0 1 2 1(c) 1 2 0 1(d) 0 2 1 1
12. Consider following declaration
typedef int (*test) ( float * , float*)
type of tmp is (a) Pointer to function of having two arguments that is pointer to float(b) int(c) Pointer to function having two argument that is pointer to float and return int(d) None of the above
13. Consider the following program:
& char *p;
& char buf[10] ={ 1,2,3,4,5,6,9,8};
& p = (buf+1)[5];
& printf(&%d& , p);
The output for this program is: (a) 5(b) 6(c) 9(d) None of the above
14. Consider the following program:
Void f(char**);
& char * argv[] = { &ab& ,&cd& , &ef& ,&gh&, &ij& ,&kl& };
& f( argv );
void f( char **p )
& t= (p+= sizeof(int))[-1];
& printf( &%s& , t);
The output for this program is: (a) ab(b) cd(c) ef(d) gh
15. Consider the following program:
#include&stdarg.h&
int ripple ( int , ...);
& num = ripple ( 3, 5,7);
& printf( & %d& , num);
int ripple (int n, ...)
& va_start( p , n);&&&&
& for (; j&n;& ++j)
&&& i =& va_arg( p , int);
&&& for (;&&& i &=i-1& )
&&&&& ++k;
The output for this program is: (a) 7(b) 6(c) 5(d) 3
16. Consider the following program:
int counter (int i)
& static int count =0;
& count = count +i;
& return (count );
& for (i=0; i &=5; i++)
&&& j = counter(i);
The value of j at the end of the execution of the this program is:(a) 10(b) 15(c) 6(d) 7
Answer With Detailed Explanation
_____________________________________________________________
The answer is (b)volatile variable isn't affected by the optimization. Its value after the longjump is the last value variable assumed. b last value is 5 hence 5 is printed. setjmp : Sets up for nonlocal goto /* setjmp.h*/ Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmp.Returns 0 when it is initially called. Lonjjmp: longjmp Performs nonlocal goto /* setjmp.h*/ Transfers control to the statement where the call to setjmp (which initialized buf) was made. Execution continues at this point as if longjmp cannot return the value 0.A nonvolatile automatic variable might be changed by a call to longjmp.When you use setjmp and longjmp, the only automatic variables guaranteed to remain valid are those declared volatile. Note: Test program without volatile qualifier (result may very)
The answer is (a)The members of structures have address in increasing order of their declaration. If a pointer to a structure is cast to the type of a pointer to its first member, the result refers to the first member.
The answer is (a)Non recursive version of the program
int& what ( int x , int& n)
& product =1;
& while(n&0)
&&& if (n%2 == 1)&
&&&&& product = product*
&&& n = n/2;
&&& val = val*
/* Code raise a number (x) to a large power (n) using binary doubling strategy */ Algorithm description
(while n&0)&
& if& next most significant binary digit of& n( power)& is one
& then multiply accumulated product by current val& ,
& reduce n(power)& sequence by a factor of two using integer division .
& get next val by multiply current value of itself&&&&&&&&&&&&&&&&&&
The answer is (c)type of a is array of int type of &a is pointer to array of int Taking a pointer to the element one beyond the end of an array is sure to work.
The answer is (b)
The answer is (c)The comma separates the elements of a function argument list. The comma is also used as an operator in comma expressions. Mixing the two uses of comma is legal, but you must use parentheses to distinguish them. the left operand E1 is evaluated as a void expression, then E2 is evaluated to give the result and type of the comma expression. By recursion, the expression E1, E2, ..., En results in the left-to-right evaluation of each Ei, with the value and type of En giving the result of the whole expression.
c=a,b;& / *yields c=a* /
d=(a,b); /* d =b& */
The answer is (a)/* ptr is pointer to array of 3 int */
The answer is (c)f1 and f2 return address of local variable ,when function exit local variable disappeared
The answer is (c)sizeof operator gives the number of bytes required to store an object of the type of its operand . The operands is either an expression, which is not evaluated ( (++i + ++ i ) is not evaluated so i remain 3 and j is sizeof int that is 2) or a parenthesized type name.
Answer 10.
The answer is (a)void(*p[2]) ( int *, int); define array of pointer to function accept two argument that is pointer to int and return int. p[0] = f1; p[1] = f2 contain address of function .function name without parenthesis represent address of function Value and address of variable is passed to function only argument that is effected is a (address is passed). Because of call by value f1, f2 can not effect b
Answer 11.
The answer is (a)
Answer 12.
The answer is (c)C provide a facility called typedef for creating new data type names, for example declaration
typedef char string
Makes the name string a synonym for int .The type string can be used in declaration, cast, etc, exactly the same way that the type int can be. Notice that the type being declared in a typedef appears in the position of a variable name not after the word typedef.
Answer 13.
The answer is (c)If the type of an expression is &array of T& for some type T, then the value of the expression is a pointer to the first object in the array, and the type of the expression is altered to &pointer to T& So (buf+1)[5] is equvalent to *(buf +6) or buf[6]
Answer 14.
The answer is (d)p+=sizeof(int) point to argv[2] (p+=sizeof(int))[-1] points to argv[1]
Answer 15.
The answer is (c)When we call ripple value of the first argument passed to ripple is collected in the n that is 3. va_start initialize p to point to first unnamed argument that is 5 (first argument).Each call of va_arg return an argument and step p to the next argument. va_arg uses a type name to determine what type to return and how big a step to take Consider inner loop
(; i&=i-1) k++ /* count number of& 1 bit in i *
in five number of 1 bits is (101) 2in seven number of 1 bits is (111) 3hence k return 5example
let& i= 9 = 1001
&&&& i-1& = 1000&&&&&&&
&&& (i-1) +1 = i
&&&&&&&&&&&&&& 1000
&&&&&&&&&&&&&&&& +1
&& &&&&&&&&&&&1 001
The right most 1 bit of i has corresponding 0 bit in i-1 this way i & i-1, in a two complement number system will delete the right most 1 bit I(repeat until I become 0 gives number of 1 bits)
Answer 16.
The answer is (b)Static variable count remain in existence rather than coming and going each time function is calledso first call counter(0) count =0second call counter(1) count = 0+1;third call counter(2) count = 1+2; /* count = count +i */fourth call counter(3) count = 3+3;fifth call counter(4) count = 6+4;sixth call counter(5) count = 10+5;
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:73925次
积分:1152
积分:1152
排名:第16153名
原创:27篇
转载:50篇
评论:14条
(2)(1)(3)(3)(1)(1)(1)(5)(4)(19)(22)(15)}

我要回帖

更多关于 求平均值的函数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信