IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Functions - Discussion

@ : Home > C Programming > Functions > Find Output of Program - Discussion

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);
}

[A]. AB[B]. BC
[C]. CD[D]. No output

Answer: Option C

Explanation:

No answer description available for this question.


Anila said: (Fri, Jul 23, 2010 09:42:06 PM)    
 
a++ increment its index t0 2.By *a means its content.so prints B.similarly next printf.

Bagesh Kumar Singh said: (Sun, Sep 19, 2010 10:39:36 PM)    
 
Here we pass the array in function. We pass the base address of the base array which is zero. a[0]=A, a[1]=B, a[2]=C, a[3]=D.

Now a++ it means increment the address of the address 1 which store the value is B. In same a++ it will be 2, which print C.

Amar said: (Wed, Oct 13, 2010 08:04:46 AM)    
 
Since the array is declared of "char" type an increment i.e. a++ would make it point to the next of its type i.e. a[1] wich is B. Same for the next one.

K Vinayak said: (Thu, Feb 3, 2011 06:14:17 AM)    
 
Here in this program we are passing the starting address of array so it is received in *a and on pointers we can perform arithmatic operations a is incremented once and printed so the result is B it is again incremented and printed so the result C.

Sridhar said: (Thu, May 12, 2011 01:18:17 AM)    
 
*a means first we should see wat is address and 2ndly for which var address belongs to and wat is the value....here the address of *a is 1 and next a++ *a+1 is a(2) value is b
and again a++ a(3) value is c

Christopher said: (Fri, Aug 12, 2011 12:54:43 PM)    
 
I agree with Bagesh Kumar singh Point.

Pratik said: (Sun, Nov 20, 2011 12:26:50 PM)    
 
Wee when we are sending the addres of a[i], and incrementing it, so automaticaly address of a[i] will shift to a[i+1]. And hence it will print the content of net address a[i+1] as *a[i] is printed.

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!