Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7067511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:12:39+00:00 2026-05-28T05:12:39+00:00

I was writing this code on codeblocks(only compiler I m having).When I encountered such

  • 0

I was writing this code on codeblocks(only compiler I m having).When I encountered such a behaviour. plz Somebody suggest why is this happening with ct, am I missing something.

#include <stdio.h>
int main(int argc,char* argv[])
{
    int lov[3][2]={0};        
    int ct=0;
    char* art;
    if(argc!=4)
        return 1;   


   art=argv[1];
        do
        {
            if(*art=='L' & *(art+1)=='o' & *(art+2)=='c')
            {
                printf("\n\n (art+3)=%s ,*(art+3)=%c ,*(art+5)=%c",(art+3),*(art+3),*(art+5) );
                lov[ct][ct]=*(art+3)-48;
                lov[ct][ct+1]=*(art+5)-48;
                printf("\nct=%d,lov[x][x]=%d,lov[x][x+1]=%d ",ct,lov[ct][ct],lov[ct][ct+1]);
                ct++;
            }
            art+=3;
        }
        while(*(art++));
getchar();
}

And on command prompt:-

>Resol.exe Loc2,5 Loc3,8 Loc5,4
Output:-


 (art+3)=2,5 ,*(art+3)=2 ,*(art+5)=5
ct=0,lov[x][x]=2,lov[x][x+1]=5

 (art+3)=3,8 ,*(art+3)=3 ,*(art+5)=8
ct=1,lov[x][x]=3,lov[x][x+1]=8

 (art+3)=5,4 ,*(art+3)=5 ,*(art+5)=4

ct=5,lov[x][x]=4198582

,lov[x][x+1]=4

Why ct becomes 5????(last Line)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:12:40+00:00Added an answer on May 28, 2026 at 5:12 am

    It would appear that ct is being overwritten because you are accessing lov out of bounds. Your compiler is probably placing ct and lov close to each other on the stack which is why ct is being modified incorrectly.

    When ct equals 1 you write to lov[ct][ct+1], which is lov[1][2]. That is out of bounds. But the next time round you write to lov[2][2] and lov[2][3] and one of those will be the one that causes the modification to ct.

    When you write lov[ct][ct+1], that can only be valid for ct == 0. All other values of ct result in out-of-bounds access of the array.

    I would not be surprised if there are other such errors given the confusing nature of this code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was writing this code in C when I encountered the following problem. #include
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I'm writing code like this, doing a little quick and dirty timing: var sw
I frequently find myself writing code like this: List<int> list = new List<int> {
I always find myself writing code like this: my $var = $result[0]; my $var_changed
Why does everyone tell me writing code like this is a bad practice? if
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
I have some code like this in a winforms app I was writing to
I copy and paste code from this URL for creating and reading/writing a proc
I'm writing code that looks similar to this: public IEnumerable<T> Unfold<T>(this T seed) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.