Login
Register
@
Dark Mode
Profile
Edit my Profile
Messages
My favorites
Register
Activity
Q&A
Questions
Unanswered
Tags
Subjects
Users
Ask
Previous Years
Blogs
New Blog
Exams
Dark Mode
Find output of following C program
komal07
asked
in
Programming in C
Jul 7, 2015
698
views
2
votes
2
votes
main(){
int a[2][3][2]={ { {1,2},{9,8},{3,7} },{ {2,3},{1,4},{5,4} } };
printf("%d %d %d", a[1]-a[0],a[1][0]-a[0][0],a[1][0][0]-a[0][0][0]);
}
A) 3 3 1
B) 3 6 1
C) 6 6 1
D) 1 1 1
Plz explain
komal07
asked
in
Programming in C
Jul 7, 2015
by
komal07
698
views
answer
comment
Follow
share this
share
0 Comments
Please
log in
or
register
to add a comment.
Please
log in
or
register
to answer this question.
2
Answers
3
votes
3
votes
a[1][0][0]-a[0][0][0]=2-1=1
a[1][0]-a[0][0]=(address of a[1][0][0]- address of a[0][0][0])/size(int)=6*sizeof(int)/sizeof(int)=6;
(note: here a[1][0] is of type int *(i.e, starting address of 1D array or Integer pointer ) hence we divide by sizeof(int) )
a[1]-[0]=(address of a[1]-address of a[0])/ sizeof(int[2])=6*sizeof(int)/sizeof(int[2])=3
(note: here a[1] is of type int (*)[2](i.e, starting address of 2D array or pointer to a Integer array int[2]) hence we divide by sizeof(int [2]) )
Hence the answer is B
Mari Ganesh Kumar
answered
Jul 7, 2015
edited
Jul 7, 2015
by
Mari Ganesh Kumar
by
Mari Ganesh Kumar
comment
Follow
share this
4 Comments
Show 2 previous comments
by
Mari Ganesh Kumar
commented
Jul 7, 2015
reply
Follow
share this
thanks for correcting me sir.. have edited my answer
0
0
by
komal07
commented
Jul 7, 2015
reply
Follow
share this
in the case when a[1] is a pointer to a 3 dimensional array we would divide by 3 to get the difference between 2 pointers?
0
0
by
Mari Ganesh Kumar
commented
Jul 8, 2015
edited
Jul 8, 2015
by
Mari Ganesh Kumar
reply
Follow
share this
a has starting address of 3D array or ID array of int [3][2]
a[0] has starting address of 2D array or ID array of int[2]
a[0][0] has starting address of 1D array or ID array of integers
a[0][0][0] is a integer.
So
a points to a element of sizeof int[3][2]
a[0] points to element of sizeof int[2]
a[0][0]points to element of sizeof int
0
0
Please
log in
or
register
to add a comment.
0
votes
0
votes
option D ...
bgfbfg
answered
Jul 18, 2015
by
bgfbfg
comment
Follow
share this
0 Comments
Please
log in
or
register
to add a comment.
← Previous
Next →
← Previous in category
Next in category →
Related questions
5
votes
5
votes
2
answers
1
Mandeep Singh
asked
in
Programming in C
Oct 22, 2016
18,130
views
Find output of the following C program
#include <stdio.h> int main() { int y = 2; int z = y +(y = 10); printf("%d\n", z); }
Mandeep Singh
asked
in
Programming in C
Oct 22, 2016
by
Mandeep Singh
18.1k
views
programming-in-c
2
votes
2
votes
3
answers
2
komal07
asked
in
Programming in C
Apr 10, 2015
1,349
views
Find output of following c program
What is the output of the following $C$ code segment? # define product (a, b) a * b main() { int x=5, y=2; print f("%d", product{x+4, y-3}); } $10$ $-9$ $15$ Error.
komal07
asked
in
Programming in C
Apr 10, 2015
by
komal07
1.3k
views
1
vote
1
vote
1
answer
3
Archies09
asked
in
Programming in C
Apr 23, 2017
3,184
views
Find the output of C program
What will be the output of the program? #include<stdio.h> int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d %d\n", k, l); return 0; }
Archies09
asked
in
Programming in C
Apr 23, 2017
by
Archies09
3.2k
views
programming-in-c
functions
0
votes
0
votes
1
answer
4
abhinowKatore
asked
in
Programming in C
Jan 18, 2023
878
views
Ace Test series |C programming | What will be the output of the following program ?
What will be the output of the following program ? answer is 8 but I am getting 5, please explain where I am wrong
abhinowKatore
asked
in
Programming in C
Jan 18, 2023
by
abhinowKatore
878
views
programming-in-c
recursion
Subscribe to GATE CSE 2024 Test Series
Subscribe to GO Classes for GATE CSE 2024
Quick search syntax
tags
tag:apple
author
user:martin
title
title:apple
content
content:apple
exclude
-tag:apple
force match
+apple
views
views:100
score
score:10
answers
answers:2
is accepted
isaccepted:true
is closed
isclosed:true
Recent Posts
Post GATE 2024 Guidance [Counseling tips and resources]
GATE CSE 2024 Result Responses
[Project Contest] Pytorch backend support for MLCommons Cpp Inference implementation
Participating in MLCommons Inference v4.0 submission (deadline is February 23 12pm IST)
IIITH PGEE 2024 Test Series by GO Classes
Subjects
All categories
General Aptitude
(3.5k)
Engineering Mathematics
(10.4k)
Digital Logic
(3.6k)
Programming and DS
(6.2k)
Programming
(4.1k)
Programming in C
(4.1k)
Programming in Python
(5)
DS
(2.0k)
Algorithms
(4.8k)
Theory of Computation
(6.9k)
Compiler Design
(2.5k)
Operating System
(5.2k)
Databases
(4.8k)
CO and Architecture
(4.0k)
Computer Networks
(4.9k)
Artificial Intelligence
(79)
Machine Learning
(48)
Data Mining and Warehousing
(25)
Non GATE
(1.4k)
Others
(2.7k)
Admissions
(684)
Exam Queries
(1.6k)
Tier 1 Placement Questions
(17)
Job Queries
(80)
Projects
(11)
Unknown Category
(870)
64.3k
questions
77.9k
answers
244k
comments
80.0k
users
Recent Blog Comments
category ?
Hi @Arjun sir, I have obtained a score of 591 in ...
download here
Can you please tell about IIT-H mtech CSE self...
Please add your admission queries here:...
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy