c语言编程题面试

C Interview Questions and Answers – Here you will find frequently asked C language interview questions and answers with suitable examples on various C language topics.

C面试问题和答案 –在这里,您会发现常见的C语言面试问题和答案,以及有关各种C语言主题的合适示例。

常见/常见的C面试问题 (Frequently /commonly asked C Interview Questions)

1) What is modular programming?

1)什么是模块化编程?

Modular programming is a program design technique in which a large program is divided into sub programs/ functions that are called modules, it improve maintainability of a program. It makes software development, debug, modify, update faster and easy.

模块化编程是一种程序设计技术,其中将大程序分为称为模块的子程序/功能,它提高了程序的可维护性。 它使软件开发,调试,修改,更新更快,更容易。

2) How many keywords & operators are used in c Language?

2)c语言中使用了多少关键字和运算符?

There are 32 keywords & 45 operators that are used in c programming language.

使用c编程语言有32个关键字和45个运算符。

3) What is variable?

3)什么是变量?

Variable is a named location with unique name, used to stored data according to the requirement.

变量是具有唯一名称的命名位置,用于根据需要存储数据。

4) What is the return type of printf() function, and what it returns ?

4)printf()函数的返回类型是什么,它返回什么?

printf() is a library function, the prototype of printf() is available in <stdio.h>, It returns a interger value, that describe how many charaters are printed on console.

printf()是一个库函数, <stdio.h>中提供了printf()的原型,它返回一个整数值,该值描述控制台上打印了多少个字符。

5) What is the return type of scanf() function, and what it returns ?

5)scanf()函数的返回类型是什么,它返回什么?

scanf() is a library function, the prototype of scanf() is availabe in <stdio.h>, It returns a integer value, that describe successful input from console in variable.

scanf()是一个库函数,在<stdio.h>中提供了scanf()的原型,它返回一个整数值,该整数值描述了从控制台成功输入变量。

6) What is full form of AT & T lab ?

6)AT&T实验室的完整形式是什么?

Americal Telegraph and Telecommunication.

美国电报和电信。

7) What is the full form of ANSI?

7) ANSI的完整形式是什么?

American National Standard Institute.

美国国家标准协会。

8) What is full form of ARM ?

8)什么是完整形式的ARM?

Advance RISC(Reduced Instruction Set Computer) Machine.

先进的RISC(精简指令集计算机)机。

9) Whenever a condition is evaluated in C language, How can we understand It is TRUE or FALSE?

9)每当使用C语言评估条件时,我们如何理解它是TRUE还是FALSE?

Every condition returns 1 when it is TRUE, and return 0 when it is FALSE.

每个条件为TRUE时返回1,为FALSE则返回0。

10) What is the difference between #include < > and #include " "?

10)#include <>和#include“”有什么区别?

#include< >: compiler searches header files in standard directory.

#include <> :编译器在标准目录中搜索头文件。

    /***header files***/
    #include < stdio.h >
    #include < math.h >

#include" ": compiler searches header files in current directory first then searches in standard directory, basically this type of inclusion used for user defined header files.

#include“” :编译器首先在当前目录中搜索头文件,然后在标准目录中搜索,基本上,这种包含类型用于用户定义的头文件。

    /***header files***/
    #include "stdio.h"
    #include "math.h"
    #include "inc/cam.h"
    

11) What is a main() and difference b/w void main() and int main()?

11)什么是main()和b / w void main()和int main()的区别?

mian() is an entry point ( main function) which is in most programming languages, When compiler begins compile the program, It looks for an entry point, and main() acts as an entry point in C program, or we can say main is a thread/ process/ function that invokes automatically by the compiler when program is being executed.

mian()是大多数编程语言中的入口点(主要功能),当编译器开始编译程序时,它会寻找一个入口点,并且main()充当C程序中的入口点,或者我们可以说main是一个线程/进程/函数,在执行程序时由编译器自动调用。

Every function returns a value to the calling function, at that time main will be a called function for compiler/OS and it will return some value to the compiler before exit, here void and int defines that main will return a void ( nothing) and int will return an integer values to the compiler.

每个函数都会向调用函数返回一个值,届时main将成为编译器/ OS的被调用函数,并且它将在退出之前向编译器返回一些值,此处的void和int定义了main将返回一个void(无),并且int将向编译器返回一个整数值。

void main() syntax

void main()语法

#include <stdio.h>
void main()
{
	statements;
	....;
	statements;
}

int main() syntax

int main()语法

#include <stdio.h>
int main()
{
    statements;
    ....;
    statements;
    return 0; /*return any integer value*/
}


12) What is an lvalue?

12)什么是左值?

An lvalue is a variable to which value can be assigned by assignment operator, this is located on the left side of assignment (=) operator, whereas rvalue is located on the right side of the assignment operator, and lvalue can not be a constant.

lvalue是可以由赋值运算符分配值的变量,它位于赋值(=)运算符的左侧,而rvalue位于赋值运算符的右侧,而lvalue不能为常数。

13) What is the difference between printf() and puts() ?

13)printf()和puts()有什么区别?

The function printf() writes the data on standard output device with the ability of formatted string using %c, %d, %s, %20s .. etc and printf does not add new line after displaying text.

函数printf()使用%c,%d,%s,%20s等将格式化的字符串写入标准输出设备的数据,并且printf在显示文本后不会添加新行。

 int printf(const char *format, ...);

puts() writes the string on standard output device and add new line after displaying text.

puts()将字符串写入标准输出设备,并在显示文本后添加新行。

 int puts(const char *s);

14) In the case of character array what is the difference b/w strlen() and sizeof() ?

14)对于字符数组,b / w strlen()和sizeof()有什么区别?

In character array strlen() returns the number of characters, while sizeof() returns the number of occupied bytes by character array.

在字符数组中,strlen()返回字符数,而sizeof()返回按字符数组占用的字节数。

Example

#include <stdio.h>
#include <string.h>

int main()
{
	char text[100]= "Sample test";
	printf("%d,%d", strlen(text), sizeof(text));
	return 0;
}

In this example strlen(text) will return 11 because total number of characters are 11 and sizeof(text) will return 100, because text variable will take 100 bytes in memory.

在此示例中, strlen(text)将返回11,因为字符总数为11, sizeof(text)将返回100,因为text变量将占用100个字节的内存。

15) When is a switch statement can be better than an if statement?

15)switch语句何时比if语句更好?

If you have more than one condition to check on single variable or a single expression, then switch is better than if. In switch statement, program’s execution jumps to the matching value if found. If you use if condition, it checks one by one condition. So it is highly recommended to use switch, if you have to check a variable/condition/expression with multiple values.

如果要检查单个变量或单个表达式的条件不只一个,那么switch比if更好。 在switch语句中,程序的执行将跳至匹配的值(如果找到)。 如果使用if条件,它将一一检查条件。 因此,如果必须检查具有多个值的变量/条件/表达式,则强烈建议使用switch。

Example

if( errorCode == 0)
	printf("Error code is 0: reading failed error.\n");
if( errorCode == 1)
	printf ("Error code is 1: writing failed error.\n");
if( errorCode == 2)
	printf("Error code is 2: opening failed error.\n");
if( errorCode == 3)
	printf("Error code is 3: write protected.\n");

Here, errorCode variable is checking with values 0,1,2 and 3. In such case you can use switch.

在这里, errorCode变量将使用值0、1、2和3进行检查。在这种情况下,可以使用switch。

switch(errorCode)
{
	case 0:
		printf("Error code is 0: reading failed error.\n");
		break;

	case 1:
		printf ("Error code is 1: writing failed error.\n");
		break;

	case 2:
		printf("Error code is 2: opening failed error.\n");
		break;

	case 3:
		printf("Error code is 3: write protected.\n");
		break;

	default:
		printf("Undefined error.\n");
}

翻译自: https://www.includehelp.com/c-programs/c-interview-questions-and-answers-page-1.aspx

c语言编程题面试

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐