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 - Const - Discussion

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

Read more:

"I never think of the future. It comes soon enough."
- Albert Einstein
3. 

What will be the output of the program?

#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10;
    const int *ptr = &i;
    fun(&ptr);
    return 0;
}
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;
    printf("Before changing ptr = %5x\n", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5x\n", *ptr);
    return 0;
}

[A]. Address of i
Address of j
[B]. 10
223
[C]. Error: cannot convert parameter 1 from 'const int **' to 'int **'
[D]. Garbage value

Answer: Option E

Explanation:

No answer description available for this question.


Shammas said: (Wed, May 18, 2011 10:23:44 PM)    
 
I can't understand the concept..

Gopu said: (Thu, May 26, 2011 12:11:17 AM)    
 
Please explain this.

Xyz said: (Tue, Jun 14, 2011 01:22:17 AM)    
 
Please anybody explain this one.

Ravi said: (Sat, Jul 2, 2011 12:47:05 AM)    
 
const pointer cannot be passed to non-const parameter.

In line :fun(&ptr);
ptr in non-const, but argument required is const **ptr .

Indu said: (Fri, Aug 5, 2011 03:21:53 PM)    
 
Can Anyone Explain?

Ranjit said: (Tue, Aug 23, 2011 08:17:19 AM)    
 
Ravi already said it.

Ptr is a const pointer. The argument of fun should be const too.

Am12Cs said: (Wed, Aug 31, 2011 10:27:46 PM)    
 
#include<stdio.h>
int fun(int **ptr);

int main()
{
int i=10;
const int *ptr = &i;{{Probably CONST INT*PTR IS ASSIGNED TO REFERENCE OF 'I' WHICH CNT BE ALTERED BUT PTR IN FUTURE CAN BE ASSIGNED SOMETHING ELSE WHICH WILL NOT GIVE AN ERROR.
const int *ptr = &i;
*PTR=12;//ERROR
ptr=10;//NO ERROR

const int *ptr = &i;
int fun(int **ptr)
{
int j = 223;
int *temp = &j;
printf("Before changing ptr = %5x\n", *ptr);
const *ptr = temp;// HERE IS THE ERROR
printf("After changing ptr = %5x\n", *ptr);
return 0;
}
}

Bond said: (Thu, Sep 8, 2011 12:31:08 AM)    
 
The ptr is declared twice in the function. How come that is not an error?

Shru said: (Fri, Sep 23, 2011 12:56:47 PM)    
 
Ravi explanation is correct.

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!