c++面试常见编程题
-
What is the difference between declaration and definition of a variable or function?
变量或函数的声明与定义之间有什么区别?
Declaration a variable and function will declare that there is a variable or function in the program but the memory allocation is not done.Generally extern keyword is used
声明一个变量和函数将声明程序中有一个变量或函数,但是没有完成内存分配。通常使用extern关键字
Definition a variable or function will allocate required memory area. Normal definitions like int is used.
定义变量或函数将分配所需的内存区域。 使用像int这样的普通定义。
-
What are storage class specifiers in C like auto?
像auto这样的C中的存储类说明符是什么?
auto, reg,ster, static ,extern
自动,reg,ster,静态,外部
-
What is scope of a variable in C?
C中变量的范围是什么?
Scope of a variable is the part of the applications where the variable can be directly accessible.
变量的范围是应用程序中可以直接访问该变量的部分。
-
What is pointer in C?
C语言中的指针是什么?
Points memory areas where a variable or function is stored. Used for efficiency and practical solutions.
指向存储变量或函数的存储区。 用于效率和实用的解决方案。
-
In which cases should we use pointers in C?
在哪种情况下,我们应该在C中使用指针?
- Getting address of a variable 获取变量的地址
- Getting address of a function获取功能地址
- Pass large data like structures between functions在函数之间传递类似结构的大数据
- To implement linked data structures实现链接的数据结构
- Share local data with other functions and code parts与其他功能和代码部分共享本地数据
In which cases should we use pointers in C?
在哪种情况下,我们应该在C中使用指针?
-
What is NULL pointer in C?
什么是C中的NULL指针?
NULL pointer points nowhere. So it is used for pointer initialization to set empty pointer.
空指针指向无处。 因此,它用于指针初始化以设置空指针。
-
What is dangling pointer in C?
什么是C中的悬空指针?
Dangling pointer is a pointer where it points invalid memory area. We can say that it is unworking pointer.
悬空指针是指向无效内存区域的指针。 我们可以说这是行不通的指针。
-
What is memory leak in C and how can we avoid?
什么是C中的内存泄漏?如何避免?
Memory leaks is a situation where application memory area is flooded. Generally occurs when heap memory area is not deleted.
内存泄漏是应用程序内存区域被淹没的情况。 通常在不删除堆内存区域时发生。
-
What are static variables in C? When we use them?
什么是C中的静态变量? 当我们使用它们?
Static variables values are hold during the applications run time. We can preserve the value for long time
静态变量值在应用程序运行时保持。 我们可以长期保留价值
-
What are static functions in C? When we use them?
什么是C中的静态函数? 当我们使用它们?
Static function can only accesses by the file they were defined.
静态函数只能通过定义的文件访问。
-
What is the difference between malloc and calloc in C?
C语言中的malloc和calloc有什么区别?
Both allocated memory but calloc fills the allocated memory with .
分配的内存和calloc都用。
-
What is difference between including header file with brackets <> and quotes “” in C?
在C中包含带括号<>的头文件和带引号“”的区别是什么?
<> will search header file in builtin paths
<>将在内置路径中搜索头文件
"" will search header file in builtin paths and current working directory
""将在内置路径和当前工作目录中搜索头文件
-
What is the association between arrays and pointers?
数组和指针之间的关联是什么?
Array variable names hold address of the first element of the array. Where it acts like a pointer.
数组变量名称保存数组第一个元素的地址。 它充当指针的地方。
-
Why we use typedef?
为什么我们使用typedef?
Typedef is used to create alias or new name for already defined type.
Typedef用于为已定义的类型创建别名或新名称。
-
What is call by value for functions in C?
C语言中的函数按值调用是什么?
While providing parameters to the function provided value is copied to the function parameter.
在向函数提供参数时,将提供的值复制到函数参数。
-
What is call by reference for functions in C?
什么是C中的引用调用?
While providing parameters to the function provided variable pointer is provided to the function parameter so there will be no copy.
在向函数提供参数时,将提供的变量指针提供给函数参数,因此不会有副本。
-
What is the difference between call by value and reference for functions in C?
在C语言中,按值调用和引用之间有什么区别?
Call by value is easier to use but data is copied which cause some performance loss
按值调用更易于使用,但复制数据会导致性能下降
Call by reference is a bit trickier but have performance gains and gives ability to access without any scope restriction.
通过引用进行调用比较棘手,但是可以提高性能,并且可以不受任何范围限制地进行访问。
翻译自: https://www.poftut.com/commonly-asked-c-programming-interview-questions-and-answers/
c++面试常见编程题