C++
西瓜LXF
这个作者很懒,什么都没留下…
展开
-
C++ vector和list的区别
1.vector数据结构vector和数组类似,拥有一段连续的内存空间,并且起始地址不变。因此能高效的进行随机存取,时间复杂度为o(1);但因为内存空间是连续的,所以在进行插入和删除操作时,会造成内存块的拷贝,时间复杂度为o(n)。另外,当数组中内存空间不够时,会重新申请一块内存空间并进行内存拷贝。2.list数据结构list是由双向链表实现的,因此内存空间是不连续的。只能通过指针访问数据,所以list的随机存取非常没有效率,时间复杂度为o(n);但由于链表的特点,能高效地进行插入和删除。转载 2021-12-03 10:59:00 · 1724 阅读 · 0 评论 -
C++ 堆栈问题
C/C++编译的程序内存分配有五个区域描述生存周期举例堆由程序员主动分配与释放new-delete malloc-freechar * p1 = (char*) malloc(10) 注意p1指针本身是在栈中的栈由编译器自动分配释放 ,存放函数的参数值,局部变量的值等函数中-函数执行网,类-类销毁时int fun(int a){int b = 2;a = 3 ;return a*b;}静态区全局变量和静态变量的存储是放在一块的,初始化的程序结束后由系原创 2021-12-03 10:52:39 · 247 阅读 · 0 评论 -
gcc和g++的对比与区别
以下说法正确的是C/C++ 中gcc和g++的对比与区别正确答案: A B D 你的答案: A D (错误)gcc编译.c文件,__cplusplus没有定义,编译器按照c编译代码gcc编译.cpp文件,__cplusplus有定义,编译器按照c++编译代码g++编译.c文件, __cplusplus没有定义,编译器按照c编译代码g++编译.cpp文件, __cplusplus有定义,编译器按照c++编译代码解析:一、区别gcc是GCC中的c编译器g++是GCC中的c++编译器原创 2021-10-11 10:55:19 · 503 阅读 · 0 评论 -
降序链表合并
题目:将两个降序链表合并为一个新的 降序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。如:{6,5,1}{8,5,2} 合并后:{8,6,5,5,2,1}ListNode* MergeTwoLists(ListNode* list1, ListNode* list2){ // write code here ListNode* node = new ListNode(-1); ListNode* node_0 = node;//备份头 while (l原创 2021-09-30 15:44:30 · 854 阅读 · 0 评论 -
C++试题6
10、下面程序运行后的结果为:char str[] = "glad to test something";char *p = str;p++;int *p1 = reinterpret_cast<int *>(p);p1++;p = reinterpret_cast<char *>(p1); printf("result is %s\n", p);正确答案: Dresult is glad to test somethingresult is ad to te原创 2021-09-23 19:18:06 · 280 阅读 · 0 评论 -
C++试题5
12、若char是一字节,int是4字节,指针类型是4字节,代码如下:class CTest{ public: CTest():m_chData(‘\0’),m_nData(0) { } virtual void mem_fun(){} private: char m_chData; int m_nData; static char s_chData;};char CTes原创 2021-09-23 19:05:51 · 279 阅读 · 0 评论 -
C++试题4
14、下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数数组中共有M个字符串,且串长小于N。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。试题程序。#define M 5 #define N 20 int fun(char(* ss)[N], int *n) { int i, k = 0, len = N; for (i = 0; i < __原创 2021-09-23 17:49:35 · 78 阅读 · 0 评论 -
c++试题3
16.In the main() function, after ModifyString(text) is called, what’s the value of ‘text’?int FindSubString( char* pch ){ int count = 0; char * p1 = pch; while ( *p1 != '\0' ) { if ( *p1 == p1[1] - 1 ) {原创 2021-09-23 17:20:12 · 119 阅读 · 0 评论 -
c++试题2
18.写出下列程序的运行结果。https://www.nowcoder.com/questionTerminal/2e8b44c677a1451d9c6662389fe31490#include "stdio.h"int sum(int a){ auto int c = 0; static int b = 3; c += 1; b += 2; return (a + b + c);}int main(){ int i; int a = 2原创 2021-09-22 21:11:16 · 104 阅读 · 0 评论 -
C++试题
https://www.nowcoder.com/questionTerminal/9884ac3aa6ee4a529b545e1bb4827b7e20.如下代码输出结果是什么?#include<stdio.h>char *myString(){ char buffer[6] = {0}; char *s = "Hello World!"; for (int i = 0; i < sizeof(buffer) - 1; i++) {原创 2021-09-22 20:16:03 · 131 阅读 · 0 评论