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 - Structures, Unions, Enums - Discussion

@ : Home > C Programming > Structures, Unions, Enums > Find Output of Program - Discussion

Read more:

"Nothing in life is to be feared, it is only to be understood."
- Marie Curie
12. 

What will be the output of the program ?

#include<stdio.h>

    struct course
    {
        int courseno;
        char coursename[25];
    };
int main()
{
    struct course c[] = { {102, "Java"}, 
                          {103, "PHP"}, 
                          {104, "DotNet"}     };

    printf("%d ", c[1].courseno);
    printf("%s\n", (*(c+2)).coursename);
    return 0;
}

[A]. 103 DotNet[B]. 102 Java
[C]. 103 PHP[D]. 104 DotNet

Answer: Option E

Explanation:

No answer description available for this question.


Praveen said: (Tue, Jul 6, 2010 02:33:27 AM)    
 
When you do c[1].courseno it will print the 'c[1]' array 1st variable ie 103 then (*(c+2)).coursename it will go into c[2] array's coursename contents.

Sivaram said: (Sun, Jan 16, 2011 04:40:09 AM)    
 
Thanks praveen.

Jitu Rahangdale said: (Fri, Feb 18, 2011 10:48:29 AM)    
 
Ok, pravin said is right. I agree with him.

Iram said: (Fri, Mar 18, 2011 06:53:35 AM)    
 
Anyone can explain in detail.

Prits said: (Thu, Jun 16, 2011 05:29:58 AM)    
 
What is use of pointer here? any special use? will anyone explain that please.

Thanks.

Apurva Nigam said: (Tue, Jun 28, 2011 06:38:37 AM)    
 
The c[1].courseno points to 103 ( hope you agreed).

In (*(c+2)).coursename , *(c+2) is same as writing c[2] that is c[2] or *(c+2) points to {104, "DotNet"}

Therefore (*(c+2)).coursename or u can say c[2].coursename will give DotNet.

Take care :)

Sravanthi Emmadi said: (Thu, Aug 4, 2011 01:21:12 PM)    
 
Thank you Apurva.

Ramdas said: (Wed, Aug 24, 2011 10:32:48 AM)    
 
When we refer c[1], it returns 103.

And when we are using (* (c+2) ). Coursename) it refers to c[2]. Coursename because c itself points to starting address of array c. C+2 is refers to c[2]address. For getting the value in that location used * deference operator.

Safi said: (Sat, Dec 31, 2011 11:03:43 AM)    
 
The struct is a user defined data type,means defines by user for avoid multiple declaration in the program body.this data type is accessed by a Dot "." operator. Fine......

Here struct for "course" variable. Now

printf("%d", c[1].courseno);

will return courseno stored at 2nd array location of c,ie c[1] bcz by default array initiates with index 0 and it is 1st location of that array...while return type in printf function is integer.....
and

printf("%d", c[1].courseno);

ans= 103

we can write c[2] as similar to (*(c+2)) and vise versa.
hence using above funda

printf("%s\n", (*(c+2)).coursename);
return type in printf function is string, therefore

it gives answer

DotNet

I thought you cleared.

Satyaprakash said: (Tue, Jan 10, 2012 07:23:58 PM)    
 
Thank you for Apurva Nigam.

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!