标签: program-entry-point

如何检查参数是否在C++中传递

我最近开始学习C++,我有点困惑argvargc.我试图通过检查大小来确定参数是否传递给程序argc,但不管有多少参数(包括没有)我传递给程序,它的大小总是如此4.

简单的例子:

int main(int argc, char** argv)
{
    std::cout << sizeof(argc); //outputs 4 with 0 or any num of arguments
    std::cout << sizeof(argv); //outputs 8 with 0 or any num of arguments
}
Run Code Online (Sandbox Code Playgroud)

我之前发现了同样的问题,我为重复它而道歉,但我发现的那些页面上的答案与这里发生的事情相矛盾.

那么,为什么argc总是4有没有其他方法来检查参数是否传递给main()

如果它是相关的我正在使用g ++进行编译.

c++ program-entry-point arguments g++ input

-1
推荐指数
1
解决办法
781
查看次数

我的C程序在新行打印-39,我无法弄清楚原因

我一直在玩,并试图为我的大学课程试验C,我找到了我的程序所做的事情,即使我没有告诉它!

我的完整代码:

#include <stdio.h>

int main(void) {
  int c;
  while ((c = getchar()) != EOF) {
    printf("%d\n", (c - '1'));
  }
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

它的输出看起来像这样:

7
6
-39
Run Code Online (Sandbox Code Playgroud)

现在,谁能告诉我为什么-39正在打印?

c printf program-entry-point stdio

-1
推荐指数
1
解决办法
55
查看次数

得到错误"在函数'_start':(.text + 0x20):对'main'的未定义引用"无法使用类似问题的答案来解决

我是c的新手,并且在函数'_start'中不断收到此错误:(.text + 0x20):对'main'的未定义引用.我知道这是一个常见的错误,但未能在此处使用其他答案来解决.

我正在尝试编译我的"main.c"和我的"memcheck.h"

我的main.c:

#include <stdio.h>
#include <stdlib.h>
#include "memcheck.h"


int main () {
  int *ptr;

    ptr = malloc(sizeof(*ptr));
    free(NULL);
return 0;
}

void *memcheck_malloc (size_t size, char *file, int line){
return NULL;
}
void memcheck_free (void *ptr, char *file, int line){
}
Run Code Online (Sandbox Code Playgroud)

我的memcheck.h:

#include <stdlib.h>

#ifndef MEMCHECK_H
#define MEMCHECK_H

#define main memcheck_main
#undef malloc
#define malloc(size) memcheck_malloc(size, __FILE__, __LINE__)
#undef free
#define free(ptr) memcheck_free(ptr, __FILE__, __LINE__)


void *memcheck_malloc (size_t size, char *file, int line);
void memcheck_free (void *ptr, …
Run Code Online (Sandbox Code Playgroud)

c linux program-entry-point

-1
推荐指数
1
解决办法
1602
查看次数

各种C++ main()签名及其效率

最近我在竞争性编程网站上看到了以下给出的代码,

   #include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define d double
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

signed main()
{ return 0; //Omitted the rest of the code
}
[Full Code][1]
Run Code Online (Sandbox Code Playgroud)

https://www.codechef.com/viewsolution/22121098

我想知道这个代码和常规C++代码int main()在CPU速度方面的效率和性能方面有什么区别,问题集通常很大.

c++ performance program-entry-point signature

-1
推荐指数
2
解决办法
117
查看次数

这个代码在任何C标准下都有效吗?

此代码是否遵循C标准(例如C89,C99,C10x)?

void 
main(int a,int b, int c, int d,char *msg){
    if(d==1){
        printf("%s\n",msg);
    }else{
        main(1,2,3,1,&"Hello Stackoverflow");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果没有,为什么?

c program-entry-point

-2
推荐指数
1
解决办法
208
查看次数

如何在空主函数中打印Hello World

我遇到了一件有趣的事情.在一次采访中,我被要求将"Hello World"打印到控制台.但主要功能必须是:

int main(void) 
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它一定不能修改!

c c++ program-entry-point

-2
推荐指数
3
解决办法
299
查看次数

为什么布尔变量会更改(C ++)?

有人可以告诉我这是怎么回事吗?

#include <iostream>
using namespace std;
int main() {
    bool x = false;
    if (x = true) { cout << "x is true" << endl; }
    if (x = false) { cout << "x is false" << endl; } 
    // for some reason always prints "x is true".
}
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚为什么我不能使用布尔方法进行按引用调用(是的,我也在擦除该方法后进行了测试),然后我意识到我的主方法中的布尔变量是自己改变的。请帮忙!

c++ variables program-entry-point boolean pass-by-reference

-2
推荐指数
1
解决办法
66
查看次数

在java中初始化Main()并寻找替代代码

我得到了以下部分 Java 代码:

public static void main(String[] args) {
  var main = new Main();
  main.start();
}
Run Code Online (Sandbox Code Playgroud)

我不明白第 2 行 (Main()) 中的初始化。

另外,Main() 的数据类型是什么?假设,我不想使用 'var' 关键字,那么我应该使用什么?

如果有任何替代代码,请告诉我。

java program-entry-point java-10

-2
推荐指数
1
解决办法
124
查看次数

Haskell 代码找出一个数字的合成

这是一个 Haskell 代码,用于计算一个不起作用的数字的合成。合数 n 的合数是直到并包括 n 的所有合数的乘积。这段代码有什么问题?

module Compositorial where

import Data.Array.ST
import Data.Array.Unboxed
import Data.Array.Base

-- multiply all composite numbers <= n
-- Use a sieve for a fast compositeness test, and multiply in a tree-like fashion
compositorial :: Int -> Integer
compositorial n = treeProd (sieve n) 4 n

-- Sieve of Eratosthenes, basic
sieve :: Int -> UArray Int Bool
sieve end = runSTUArray $ do
    ar <- newArray (0,end) False
    let mark step idx
            | idx …
Run Code Online (Sandbox Code Playgroud)

haskell program-entry-point module

-2
推荐指数
1
解决办法
48
查看次数

在 go 中出错:func main 未使用

我在 Go 中编写了一个简单的代码,但出现了一个奇怪的错误。我附上了代码和错误的截图。

error: func main is unused
Run Code Online (Sandbox Code Playgroud)

代码:

package structs

import "fmt"

func main() {
    fmt.Println("Hello Structs")
}
Run Code Online (Sandbox Code Playgroud)

截屏:

在此处输入图片说明

program-entry-point go

-2
推荐指数
1
解决办法
67
查看次数