面试c/c++的面试问题_C面试问答

面试c/c++的面试问题

Here are 50+ commonly asked C interview questions and answers which will definitely help you out to crack one of the toughest interviews.

这里有50多个C面试常见问题和答案,这些绝对可以帮助您攻克最艰难的面试之一。

1. What is the difference between sprintf() and printf() method? The sprint() method works similar to the printf() method except for one small reason. printf() method writes the Output onto the Console screen whereas sprintf() method writes the output to an Array of Characters.

1. sprintf()和printf()方法有什么区别? sprint()方法的工作原理与printf()方法类似,但有一个小原因。 printf()方法将输出写入控制台屏幕,而sprintf()方法将输出写入字符数组。

2. When is it required to use an External Data type for a variable? External variables are also called as Global variables. External should be used if you need a single variable to be accessed by multiple functions.

2.什么时候需要对变量使用外部数据类型? 外部变量也称为全局变量。 如果需要多个功能访问单个变量,则应使用外部变量。

3. What is the range of values for an integer in C? 16-bit compiler: -32768 to 32767 32-bit compiler: – 2147483648 to 2147483647

3. C中整数的值范围是多少? 16位编译器:-32768至32767 32位编译器:– 2147483648至2147483647

C Interview Questions and Answers

4. What is Call By Reference passing method? In call by reference method, parameters are passed to other methods using their addresses. Eg.: function1(&a,&b). Here, we are passing the address location number of a and b to the function1. This strategy manipulates the Actual Arguments.

4.什么是“按引用调用”传递方法? 在按引用调用方法中,参数使用其地址传递给其他方法。 例如:function1(&a,&b)。 在这里,我们将a和b的地址位置编号传递给function1。 该策略操纵实际参数。

5. Enlist the Advantages of Macros over Variables. The advantages of using Macros over variables are as follows: A Compiler can generate faster and compact code for constants that for variables. There is always a risk that a variable may inadvertently get manipulated in the program.

5.发挥宏优于变量的优势。 使用宏而不是变量的优点如下: 编译器可以为变量的常量生成更快,更紧凑的代码。 始终存在可能在程序中无意中操纵变量的风险。

6. What is the difference between || and |? || is a Logical Operator and it is pronounced as OR Operator, whereas | is a Bitwise OR Operator.

6. ||和有什么不一样? 和|? || 是逻辑运算符,发音为“或”运算符,而| 是按位或运算符。

7. What is a continue keyword used for? The Continue keyword allows us to transfer the program control back to the very first Line of the current Loop thereby bypassing the next statements after the Keyword. A Continue is usually associated with IF Block.

7.连续关键字的作用是什么? Continue关键字允许我们将程序控制权转移回当前循环的第一行,从而绕过关键字之后的下一条语句。 继续通常与IF块关联。

8. How can you make scanf() method accept Multi-Word Strings? Scanf() function accepts a single string by default. However, a scanf() method can accept Multi-Word Strings by using the following method: scanf(“%[^\n]s”,str); This way a scanf() method takes in input until an Enter Key is Hit.

8.如何使scanf()方法接受多字字符串? Scanf()函数默认情况下接受单个字符串。 但是,scanf()方法可以使用以下方法接受多字字符串: scanf(“%[^ \ n] s”,str); 这样,scanf()方法将接受输入,直到按下Enter键为止。

9. What is the difference between ‘A’ and “A”? ‘A’ is a Character Constant whereas “A” is a String Constant.

9.“ A”和“ A”有什么区别? “ A”是字符常量,而“ A”是字符串常量。

10. Does Linux Ubuntu supports the Header file conio.h? No, the GCC Library in Linux Ubuntu does not contain definitions for conio.h header file.

10. Linux Ubuntu是否支持头文件conio.h? 不,Linux Ubuntu中的GCC库不包含conio.h头文件的定义。

11. What is the Format specifier or accessing Address using Pointers in Windows and Linux? Address Access Specifier in Windows: %u Address Access Specifier in Linux: %p

11.在Windows和Linux中,格式说明符或使用指针访问地址是什么? Windows中的地址访问说明:%u Linux中的地址访问说明:%p

12. Describe Modulus Operator? Modulus Operator is used to fetch the Remainder value on dividing one Integer with another Integer. Modulus operator cannot work with Float values. Eg.: 10%2=0

12.描述模运算符? 模运算符用于在将一个Integer除以另一个Integer时获取Remainder值。 模运算符不能使用浮点值。 例如:10%2 = 0

13. Is an Else Block necessary for a Corresponding if Block? No, an If Block is generally independent of an Else Block. An Else Block is used only when a Conditional Approach is to be used.

13.相应的if块是否需要Else块? 不,If块通常独立于Else块。 仅当使用条件方法时才使用其他块。

14. What is the difference between && and &? && is a Logical Operator and it is pronounced as AND Operator, whereas & is a Bitwise AND Operator.

14. &&和&和有什么区别? &&是逻辑运算符,发音为AND运算符,而&是按位AND运算符。

15. Enlist Comparison Operator and Assignment Operator. An Assignment Operator is used to assign or set a value to a variable whereas a Comparison Operator is used to check a condition. Assignment Operator: = Comparison Operator: ==

15.招募比较运算符和赋值运算符。 赋值运算符用于为变量赋值或设置值,而比较运算符用于检查条件。 赋值运算符:= 比较运算符:==

16. Explain Conditional Operator. Conditional Operator is also called as Ternary Operator. The Syntax for a Conditional Operator is: expression 1 ? expression 2 : expression 3 Expression 1 includes the Condition. Depending upon its value, if the Condition evaluates to be True, expression 2 will be executed and if the Expression 1 evaluates to be False, expression 3 will be evaluated.

16.解释条件运算符。 条件运算符也称为三元运算符。 条件运算符的语法为:表达式1? 表达式2:表达式3 表达式1包含条件。 根据条件的值,如果“条件”的值为“真”,则将执行表达式2;如果表达式1的值为“ False”,则将对表达式3进行求值。

17. What is the difference between Do While Loop and While Loop? A While Loop checks the Condition before executing the following set of statements whereas a Do-While Loop first executes the set of statements once and then checks the condition. In this, statement will be executed at least once even if the Condition evaluates to be False.

17.做While循环和While循环有什么区别? While循环在执行以下语句集之前检查条件,而Do-While循环首先执行一次语句集,然后检查条件。 在这种情况下,即使条件评估为False,语句也将至少执行一次。

18. What is a break keyword used for? The keyword break allows us to transfer the Control to the very first statement that occurs after the current Loop. It therefore takes the Execution Control out of the Loop. A Break is generally used with IF Blocks and Switches.

18. break关键字有什么用? 关键字break允许我们将Control转移到当前Loop之后出现的第一条语句。 因此,它将执行控制带出循环。 中断通常与IF块和开关一起使用。

19. What is the Advantage of a Switch Case Structure over an IF Block? A Switch Case Structure leads to a more structured program and the level of indentation is manageable, more so, if there are multiple statements with each case of a Switch.

19.交换盒结构比IF块有什么优势? Switch Case Structure导致程序的结构更合理,缩进级别是可管理的,如果Switch的每种情况下都有多个语句,则缩进级别更易于管理。

20. Enlist Limitations of Switch Case Structure? A Float expression cannot be tested in a Switch Case. A Case can never have Variable expression such as c + 5. It is illegal to use same expressions for multiple cases.

20.受到交换机案例结构的限制吗? 无法在Switch Case中测试Float表达式。 Case永远不能具有诸如c + 5之类的变量表达式 。在多个case中使用相同的表达式是非法的。

21. What is the significance of a Null Character in String? A Null Character is represented by \0. It is different than 0. Null Character is a terminating Character for an Array of Characters i.e., a String. It is the only way to track the end of a String.

21.字符串中的Null字符的含义是什么? 空字符由\ 0表示。 它不同于0。空字符是字符数组(即字符串)的终止字符。 这是跟踪字符串结尾的唯一方法。

22. What is the difference between function() and function(); ? function() includes the definition of the function whereas function(); is the declaration syntax of a function.

22. function()和function()有什么区别? function()包含函数的定义,而function(); 是函数的声明语法。

23. What is the role of a return statement? On executing the return statement, it immediately transfers the control back to the Calling function. It returns the value present in the parentheses after return statement to the calling function.

23.返回声明的作用是什么? 在执行return语句时,它立即将控件转移回Calling函数。 将return语句后括号中的值返回给调用函数。

24. Explain Automatic Storage Class. Syntax: auto int a; Storage: Memory Life: Till the control remains within the block in which the variable is defined. Default Initial Value: Garbage Value Scope: Local to the block in which variable is initialized

24.解释自动存储类。 语法:auto int a; 存储:内存 寿命:直到控件保留在定义变量的块内。 默认初始值:垃圾值 范围:局部于初始化变量的块

25. What is the difference between scanf() and gets() methods? scanf() method cannot accept Multi-Word Strings (that includes a Space character) whereas gets() method can help to accept Multi-Word Strings.

25. scanf()和gets()方法有什么区别? scanf()方法不能接受多单词字符串(包括空格字符),而gets()方法可以帮助接受多单词字符串。

26. Explain Calling Convention in user defined functions? It describes primarily two things: The order in which the arguments are passed to the function. It also mentions which function performs the cleanup of variables when the control returns from the function. The most commonly used convention is Standard Calling Convention.

26.在用户定义的函数中解释调用约定? 它主要描述了两件事: 将参数传递给函数的顺序。 它还提到当控件从该函数返回时,哪个函数执行变量的清除。 最常用的约定是标准呼叫约定。

27. What is Call By Value passing method? In call by value method, parameters are passed to other methods using their values. Eg.: function1(a,b) Here, we are passing values of a and b to the function1.

27.什么是按值调用传递方法? 在按值调用方法中,参数使用其值传递给其他方法。 例如:function1(a,b) 在这里,我们将a和b的值传递给function1。

28. What is a De-Referencing Operator? A De-Referencing Operator is denoted by an Asterisk *. It is used to store the Address of an Identifier in C programming.

28.什么是去引用运算符? 解引用运算符由星号*表示。 它用于在C编程中存储标识符的地址。

29. Enlist Storage Classes in C Programming Language. The Storage Classes are as follows: Automatic Storage Class Register Storage Class Static Storage Class External Storage Class

29.使用C编程语言注册存储类。 存储类如下: 自动存储类 寄存器存储类 静态存储类 外部存储类

30. Explain Register Storage Class. Syntax: register int a; Storage: CPU registers Life: Till the control remains within the block in which the variable is defined. Default Initial Value: Garbage value Scope: Local to the block in which variable is initialized

30.解释寄存器存储类。 语法:register int a; 存储:CPU寄存器 寿命:直到控件保留在定义变量的块内。 默认初始值:垃圾值 范围:局部于初始化变量的块

31. What is the difference between getch() and getche() methods? Both these methods allows the user to read a single character the instant it is typed without waiting for a Enter key to be pressed. However, in getche() method, the character is echoed after it is typed whereas in getch() method, no Echo of character is there.

31. getch()和getche()方法有什么区别? 这两种方法均允许用户在键入单个字符时立即读取单个字符,而无需等待按下Enter键。 但是,在getche()方法中,键入字符后将回显该字符,而在getch()方法中,则不存在该字符的Echo。

32. When is it required to use a Static Data type for a variable? A Static storage class should be used only when you want the value of a variable to be persistent between different functions of the same program

32.什么时候需要对变量使用静态数据类型? 仅当您希望变量的值在同一程序的不同函数之间保持不变时,才应使用静态存储类。

33. What is the difference between getchar() and fgetchar() methods? The major difference between the two is that getchar() is a Macro while fgetchar() is a Function.

33. getchar()和fgetchar()方法有什么区别? 两者之间的主要区别是getchar()是宏,而fgetchar()是Function。

34. Explain Static Storage Class. Syntax: static int a Storage: Memory Life: Value persists between different functions Default Initial Value: Zero Scope: Local to the block in which variable is initialized

34.解释静态存储类。 语法:static int 存储:内存 寿命:值在不同函数之间保留 默认初始值:0 范围:局部于初始化变量的块

35. When is it required to use an Auto Data type for a variable? This is probably the most common data type used for any variable. The prefix auto is not mandatory. If you don’t have any special need of a variable, automatic storage class is the one that you should opt for.

35.什么时候需要对变量使用自动数据类型? 这可能是用于任何变量的最常见的数据类型。 前缀auto不是必需的。 如果您对变量没有任何特殊需要,则应该选择自动存储类。

36. What is pragma directive? This is a special purpose directive that can be used to turn on or off certain features. It can help you to terminate the Warnings or any other errors. There are numerous pragma directives available in C and these are as follows: #pragma startup #pragma exit #pragma warn

36.什么是编译指示? 这是一个特殊用途的指令,可用于打开或关闭某些功能。 它可以帮助您终止警告或任何其他错误。 C中有许多可用的编译指示,它们如下: #pragma startup #pragma exit #pragma warn

37. When is it required to use a Register Data type for a variable? Since there are few CPU registers available in the memory, register storage class should be used only when a variable is being used very often

37.什么时候需要为变量使用寄存器数据类型? 由于内存中可用的CPU寄存器很少,因此仅在经常使用变量时才应使用寄存器存储类

38. Enlist the Steps in the Building Process of a C Program. A C Program is executed with the following steps: C Source Code File Expanded Source Code Assembly Code Linking Object Code of other Libraries Executable Code

38.征集C程序构建过程中的步骤。 AC程序按以下步骤执行: C源代码文件 扩展源代码 汇编代码 链接其他库的目标代码 可执行代码

39. Enlist the Operations that can be performed on a Pointer. The Operations that can be executed using a Pointer in C are as follows: Addition of a Number to Pointer Subtraction of a Number from a Pointer Subtraction of one Pointer from another Comparison of Two pointer variables

39.列出可以在指针上执行的操作。 可以使用C中的指针执行的操作如下: 将数字加到指针 减去一个指针的数字后再 减去一个指针又将另一个 指针 减去 两个指针变量的比较

40. Explain External Storage Class. Syntax: extern int a; Storage: Memory Life: As long as program doesn’t stop execution Default Initial Value: Zero Scope: Global

40.解释外部存储类别。 语法:extern int a; 存储:内存 寿命:只要程序不停止执行, 默认初始值:零 范围:全局

41. What is a String? A String is a One Dimensional Array of Characters that is terminated by a Null Character (‘\0’). Eg.: char name[]=”thecrazyprogrammer”;

41.什么是字符串? 字符串是一维字符数组,以空字符('\ 0')终止。 例如:char name [] =“ thecrazyprogrammer”;

42. What is a NULL Pointer? A NULL Pointer is a special reserved value of a Pointer. A Null Pointer therefore, points to Nothing. It doesn’t have any Address assigned to it at the time of declaration. Hence, when a Pointer has NULL value, it is not pointing to anywhere. A NULL Pointer is useful when you don’t have any location address to be assigned to the pointer at the time of Declaration.

42.什么是空指针? 空指针是指针的特殊保留值。 因此,空指针指向空。 在声明时,它没有分配任何地址。 因此,当Pointer的值为NULL时,它不会指向任何地方。 当您在声明时没有任何位置地址分配给指针时,NULL指针很有用。

43. Are 0 and ‘\0’ same? If not, explain. No, 0 and ‘\0’ are different. ASCII Value of ‘\0’ is 0 whereas that of 0 is 48. ‘\0’ is a terminating character normally used in Strings. Its the only way that functions within a string can know where the String ends. ‘\0’ is a single character.

43. 0和'\ 0'是否相同? 如果没有,请解释。 不,0和'\ 0'不同。 ASCII值'\ 0'为0,而值0为48。'\ 0'是字符串中通常使用的终止字符。 这是字符串中的函数可以知道字符串结尾的唯一方法。 '\ 0'是一个字符。

44. What is the difference between char const *p and const char* p ? In char const *p, pointer p is constant. Therefore, it is not possible to make p point to another location. However, you can modify the value of the Character referenced by p. In const char* p, the character referred by p’ is a constant and therefore it is not possible to change the value of p. However, it is possible to make p point to another location.

44. char const * p和const char * p有什么区别? 在char const * p中,指针p是常量。 因此,不可能使p指向另一个位置。 但是,您可以修改p引用的字符的值。 在const char * p中,p'所指的字符是常数,因此无法更改p的值。 但是,可以使p指向另一个位置。

45. What is the primary difference between a Declaration and a Definition? While declaring a variable, we only specify the Data Type associated to it. There’s no memory allocation at this point. However, when we define a Variable into the system, an initial value is thereby assigned to the variable and there’s memory allocation given to that particular variable.

45.宣言和定义之间的主要区别是什么? 在声明变量时,我们仅指定与其关联的数据类型。 此时没有内存分配。 但是,当我们在系统中定义一个变量时,就会为该变量分配一个初始值,并为该特定变量分配了内存。

46. What is ferror() method used for? ferror() method is a Standard Library Function. It signifies errors that occurs during a File Write or Read Operation. It returns 0 if the Read/Write Operation is successful and a Non-Zero value in case of a failure.

46. ferror()方法用于什么? ferror()方法是标准库函数。 它表示在文件写入或读取操作期间发生的错误。 如果读/写操作成功,则返回0;如果失败,则返回非零值。

47. What is a Void Pointer? A Void Pointer is a specific type of Pointer that points to the address of a data that does may have any specific data type associated with it. A Void pointer is also known as a Generic Pointer. A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type.

47.什么是空指针? 空指针是指针的一种特定类型,它指向可能与任何特定数据类型相关联的数据的地址。 空指针也称为通用指针。 使用void关键字作为指针的类型,可以像声明普通指针一样声明void指针。

48. What is #undef Directive? Sometimes, it is needed to modify a pre-defined name to be undefined for different reasons. This undefining is without deleting that name from the name. This can be established by using a Undef Directive. Suppose, if you want to Undefine a Macro that has been previously defined, you can use the following syntax: #undef macro_name

48.什么是#undef指令? 有时,出于各种原因,需要将预定义名称修改为未定义。 取消定义操作不会从名称中删除该名称。 这可以通过使用Undef指令来建立。 假设,如果要取消定义先前定义的宏,则可以使用以下语法: #undef macro_name

49. How can we refer to the Base Address of a 1D Array? The following methods would work to access the Base Address of an Array: *num *(num+0)

49.我们如何引用一维数组的基址? 以下方法可以访问数组的基地址: * num *(num + 0)

50. What is modular programming approach? Modular programming is the process of breaking down a program into parts so as to reduce the complexity of a large program. Such parts are nown as Functions. Each function performs a particular task and is generally interconnected to convey data between other functions of the same program.

50.什么是模块化编程方法? 模块化编程是将程序分解为多个部分,从而降低大型程序的复杂性的过程。 这些部分现在称为功能。 每个功能执行特定的任务,并且通常相互连接以在同一程序的其他功能之间传递数据。

51. Explain the types of Errors in C Programming. Run Time Errors: These errors are usually caught by the compilers and occur due to illegal operations performed within a program such as Dividing an Integer by Zero, Unavailability of Memory Space and others. These errors terminate the program abruptly.

51.解释C编程中的错误类型。 运行时错误: 这些错误通常由编译器捕获,并且是由于程序内执行的非法操作(例如,将整数除以零,内存空间不可用等)引起的。 这些错误会突然终止程序。

Compile Time Errors: Compilation Errors are those that occurs at the Compilation Time of a program. These errors are further divided into:

编译时错误: 编译错误是在程序的编译时发生的那些错误。 这些错误进一步分为:

Semantic Errors These errors occur due to undefined operations such as illegal assignment as this x+y=z.

语义错误 这些错误是由于未定义的操作(例如x + y = z的非法分配)而发生的。

Syntax Errors These errors occur if we don’t follow the guidelines and rules prescribed by that particular language.

语法错误 如果我们不遵循特定语言规定的准则和规则,则会发生这些错误。

Logical Errors Logical errors are most difficult to debug as these are not usually caught by the Compiler. These generally occur due to Algorithm and Logic issues within the program.

逻辑错误 逻辑错误最难调试,因为编译器通常不捕获这些错误。 这些通常是由于程序中的算法和逻辑问题而发生的。

52. What is recursion? When a Function calls itself again and again, it is called a recursive function. The Function calls itself till a particular condition does not evaluates to False. Recursion can be used to replace complex nesting code by dividing the problem into same problem of its sub-type.

52.什么是递归? 当函数一次又一次地调用自身时,它称为递归函数。 该函数将自行调用,直到特定条件的计算结果不为False为止。 通过将问题分为子类型的相同问题,可以使用递归来替换复杂的嵌套代码。

53. What is a Dangling Pointer? A Dangling Pointer occurs during Destruction of an Object when an object that has an incoming reference that is de-allocated or deleted without modifying the value of the Pointer. This is done to make the Pointer still point to the Memory location of the de-allocated memory.

53.什么是悬空指针? 当对象具有销毁或删除而未修改指针值的传入引用的对象时,在对象销毁期间会发生悬挂指针。 这样做是为了使指针仍然指向已取消分配内存的“内存”位置。

54. What is the difference between char str[]=”Interview” and char *p=”Interview”? Char *p=”Interview” In this case, p acts as a Pointer to a Constant String. Char str[]=”Interview” In this case, str acts as a Constant Pointer to a String.

54. char str [] =” Interview”和char * p =” Interview”有什么区别? Char * p =“ Interview” 在这种情况下,p充当常量字符串的指针。 Char str [] =“ Interview” 在这种情况下,str充当字符串的常量指针。

So this was the list of some important C interview questions and answers. If you found any information incorrect or missing in above list then please mention it by commenting below.

因此,这是一些重要的C面试问题和答案的列表。 如果您在上面的列表中发现任何不正确或缺失的信息,请在下面的评论中提及。

翻译自: https://www.thecrazyprogrammer.com/2015/10/c-interview-questions-and-answers.html

面试c/c++的面试问题

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值