By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

Urgent help about my code....

P: n/a
i have thiscode and i have to figure out what character would be
displayed at line 23 but they are using this f1 functin so i am
confused.... please help me which character would be displayed?
12 char f1(char a) {
13 if(a < 'a') return a + ('a' - 'A');
14 else return a;
15 } // end f1
16 char f1(int a) {
17 if(a < 'a') return a;
18 else return a - ('a' - 'A');
19 } // end f1
20 int main (int argc, char **argv)
21 {
22 char reply;
23 cout << f1('M'+1) << endl;

Mar 22 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ia*************@gmail.com wrote:
i have thiscode and i have to figure out what character would be
displayed at line 23 but they are using this f1 functin so i am
confused.... please help me which character would be displayed?
Have you tried it?
>
12 char f1(char a) {
13 if(a < 'a') return a + ('a' - 'A');
14 else return a;
15 } // end f1
16 char f1(int a) {
17 if(a < 'a') return a;
18 else return a - ('a' - 'A');
19 } // end f1
20 int main (int argc, char **argv)
21 {
22 char reply;
23 cout << f1('M'+1) << endl;

--
Ian Collins.
Mar 22 '07 #2

P: n/a
In article <11**********************@d57g2000hsg.googlegroups .com>,
ia*************@gmail.com wrote:
i have thiscode and i have to figure out what character would be
displayed at line 23 but they are using this f1 functin so i am
confused...
Compile and run it...
please help me which character would be displayed?
12 char f1(char a) {
13 if(a < 'a') return a + ('a' - 'A');
14 else return a;
15 } // end f1
16 char f1(int a) {
17 if(a < 'a') return a;
18 else return a - ('a' - 'A');
19 } // end f1
20 int main (int argc, char **argv)
21 {
22 char reply;
23 cout << f1('M'+1) << endl;
"They" are outputing the result of the function call when 'M' + 1 is
passed in is 'M' + 1 < 'a'? if it is, then the function returns ('M' +
1) + ('a' - 'A'), otherwise it returns 'M' + 1.
Mar 22 '07 #3

P: n/a
so mainly i need to say if it is smaller than 'a' then it is displayed
as ('M' +
1) + ('a' - 'A'), otherwise it returns 'M' + 1.
Mar 22 '07 #4

P: n/a
On Mar 22, 7:01 pm, ianenis.tiry...@gmail.com wrote:
i have thiscode and i have to figure out what character would be
displayed at line 23 but they are using this f1 functin so i am
confused.... please help me which character would be displayed?

12 char f1(char a) {
13 if(a < 'a') return a + ('a' - 'A');
14 else return a;
15 } // end f1
16 char f1(int a) {
17 if(a < 'a') return a;
18 else return a - ('a' - 'A');
19 } // end f1
20 int main (int argc, char **argv)
21 {
22 char reply;
23 cout << f1('M'+1) << endl;
I think it's an 'n'.
'M' + 1 = 'N'
'N' is < 'a';
so 'N' + 'a' - 'A' = 'n'

Mar 22 '07 #5

P: n/a
On Mar 22, 11:01 pm, ianenis.tiry...@gmail.com wrote:
i have thiscode and i have to figure out what character would be
displayed at line 23 but they are using this f1 functin so i am
confused.... please help me which character would be displayed?

12 char f1(char a) {
13 if(a < 'a') return a + ('a' - 'A');
14 else return a;
15 } // end f1
16 char f1(int a) {
17 if(a < 'a') return a;
18 else return a - ('a' - 'A');
19 } // end f1
20 int main (int argc, char **argv)
21 {
22 char reply;
23 cout << f1('M'+1) << endl;
The answer is implementation defined, i.e. it depends on which
computer/operating system you run it on.
If the operating system uses EBCDIC (e.g. IBM AS/400 computers), then
a different output will occur than if the system uses the ASCII
system.
I have not tested it but it looks like it will output the "RES ENP"
control character.

Mar 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.