下面给出的代码是错误的吗? [英] Is the below given code is wrong?

查看:74
本文介绍了下面给出的代码是错误的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>

int main()
{
    int a;
    printf(scanf("%d",&a));
    return 0;
}

我收到此消息分段错误(核心已转储)"

I got this message "Segmentation fault (core dumped)"

推荐答案

printf()函数的格式为:-

printf(const char *format, ...)

您必须提供 string (带有格式说明符的 format字符串)作为函数printf()的参数.

You have to provide a string (format string with format specifiers) as argument for function printf().

您可以尝试:-

printf("%d",scanf("%d",&a)); // with format string

如果扫描成功,将打印 1 .此处,%d格式字符串用于integer参数.

This will print 1 if scanning is successful . Here %d in format string for integer parameter.

要读取和打印变量a,请尝试:-

To read and print variable a , Try :-

 scanf("%d",&a);  // reading
 printf("%d",a);  // printing

这篇关于下面给出的代码是错误的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆