C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 7)
7.
What will be the output of the program?
#include<stdio.h>

int main()
{
    void fun(char*);
    char a[100];
    a[0] = 'A'; a[1] = 'B';
    a[2] = 'C'; a[3] = 'D';
    fun(&a[0]);
    return 0;
}
void fun(char *a)
{
    a++;
    printf("%c", *a);
    a++;
    printf("%c", *a);
}
AB
BC
CD
No output
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
40 comments Page 3 of 4.

Anitha said:   9 years ago
Please, anyone explain, what is the exact difference between pre increment and post increment?

Pravallika said:   7 years ago
First, we print a value after we perform post-increment operation (i.e) output become a AB.
(1)

Pratima said:   8 years ago
a++ is a postfix operation so it should increase the value after the statement, so why BC??

Pallavi Kedarkar said:   4 years ago
Is it possible to declare user define a function in main function?

Please anyone explain.
(1)

Anila said:   2 decades ago
a++ increment its index t0 2.By *a means its content.so prints B.similarly next printf.

Atib said:   1 decade ago
The function is not declared before it is invoked, why is the code still running fine?

Bhumi said:   8 years ago
void fun(char *a) is not declared before main. So why it is not giving an error?

Csk said:   1 decade ago
Why we not use fun(*a[0])instead of fun(&a[0])?

@Rishabh. Please tell me.

Shri said:   1 decade ago
a[0]='A' Store a[0]=97.

Then a++=98=B.

a++=99=C.

So that Answer is BC.

Haritha said:   1 decade ago
First a is initialized to 0. Then post increment follows.

Ans:BC.


Post your comments here:

Your comments will be displayed after verification.